main.go 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "net/http"
  6. _ "net/http/pprof"
  7. "github.com/zu1k/proxypool/internal/cron"
  8. _ "github.com/mkevac/debugcharts"
  9. "github.com/zu1k/proxypool/api"
  10. "github.com/zu1k/proxypool/internal/app"
  11. "github.com/zu1k/proxypool/pkg/proxy"
  12. )
  13. var (
  14. debugMode = false
  15. configFilePath = ""
  16. )
  17. func main() {
  18. flag.StringVar(&configFilePath, "c", "", "path to config file: source.yaml")
  19. flag.BoolVar(&debugMode, "d", false, "debug mode")
  20. flag.Parse()
  21. if debugMode {
  22. go pprof()
  23. }
  24. if configFilePath == "" {
  25. app.NeedFetchNewConfigFile = true
  26. app.FetchNewConfigFileThenInit()
  27. } else {
  28. err := app.InitConfigAndGetters(configFilePath)
  29. if err != nil {
  30. fmt.Println(err)
  31. }
  32. }
  33. proxy.InitGeoIpDB()
  34. go cron.Cron()
  35. fmt.Println("Do the first crawl...")
  36. go app.CrawlGo()
  37. api.Run()
  38. }
  39. func pprof() {
  40. ip := "127.0.0.1:6060"
  41. if err := http.ListenAndServe(ip, nil); err != nil {
  42. fmt.Printf("start pprof failed on %s\n", ip)
  43. }
  44. }