Skip to content

Commit

Permalink
Fixes #8 Add custom user-agent config file support
Browse files Browse the repository at this point in the history
  • Loading branch information
colorfulsing committed Aug 27, 2021
1 parent 309fe1b commit 7bf8c75
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/DataHenHQ/tillup/interceptors"
"github.com/DataHenHQ/tillup/logger"
"github.com/DataHenHQ/tillup/sessions"
"github.com/DataHenHQ/useragent"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -39,6 +40,16 @@ var serveCmd = &cobra.Command{
if proxy.ForceUA {
fmt.Printf("Till is currently configured to override all User-Agent headers with random %v browsers\n", proxy.UAType)
}
uaConfigFile := viper.GetString("ua-config-file")
if uaConfigFile != "" {
err := useragent.LoadUAConfig(uaConfigFile)
if err != nil {
fmt.Println("Problem loading the ua-config-file:", err)
fmt.Println("aborting server")
return
}
fmt.Printf("Using ua-config-file to generate user-agent: %v\n", uaConfigFile)
}

// set the Token
token := viper.GetString("token")
Expand Down Expand Up @@ -183,6 +194,11 @@ func init() {
log.Fatal("Unable to bind flag:", err)
}

serveCmd.Flags().String("ua-config-file", "", "Specify the path to a JSON file that contains a custom user-agent configuration.")
if err := viper.BindPFlag("ua-config-file", serveCmd.Flags().Lookup("ua-config-file")); err != nil {
log.Fatal("Unable to bind flag:", err)
}

serveCmd.Flags().String("proxy-file", "", "Specify the path to a txt file that contains a list of proxies")
if err := viper.BindPFlag("proxy-file", serveCmd.Flags().Lookup("proxy-file")); err != nil {
log.Fatal("Unable to bind flag:", err)
Expand Down

0 comments on commit 7bf8c75

Please sign in to comment.