proxy.go 584 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package database
  2. import (
  3. "github.com/zu1k/proxypool/pkg/proxy"
  4. "gorm.io/gorm"
  5. )
  6. type Proxy struct {
  7. gorm.Model
  8. proxy.Base
  9. Link string
  10. Identifier string `gorm:"unique"`
  11. }
  12. func InitTables() {
  13. if DB == nil {
  14. err := connect()
  15. if err != nil {
  16. return
  17. }
  18. }
  19. err := DB.AutoMigrate(&Proxy{})
  20. if err != nil {
  21. panic(err)
  22. }
  23. }
  24. func SaveProxyList(pl proxy.ProxyList) {
  25. proxies := make([]Proxy, pl.Len())
  26. for i, p := range pl {
  27. proxies[i] = Proxy{
  28. Base: *p.BaseInfo(),
  29. Link: p.Link(),
  30. Identifier: p.Identifier(),
  31. }
  32. }
  33. DB.Create(&proxies)
  34. }