Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Root is the root of the commands. Root = &cobra.Command{ Use: "go-vanity", SilenceErrors: true, SilenceUsage: true, Short: "go-vanity handles go vanity redirect requests", Long: `go-vanity handles go vanity redirect requests and is available for deployment via docker. More documentation at https://go.krishnaiyer.dev/go-vanity-docker`, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { err := manager.Unmarshal(config) if err != nil { panic(err) } return nil }, Run: func(cmd *cobra.Command, args []string) { baseCtx := context.Background() ctx, cancel := context.WithCancel(baseCtx) defer cancel() h, err := handler.Init(ctx, config.Redirects) if err != nil { log.Fatal(err.Error()) } var address string if address = addressRegex.FindString(config.HTTPAddress); address == "" { log.Println(fmt.Sprintf("Invalid or empty server address %s using 0.0.0.0:8080", config.HTTPAddress)) address = "0.0.0.0:8080" } r := mux.NewRouter() r.HandleFunc("/", h.HandleIndex) addPath(r, h.HandleImport, config.NoOfSubPaths) r.Methods("GET") s := &http.Server{ Handler: r, Addr: address, WriteTimeout: 5 * time.Second, ReadTimeout: 5 * time.Second, IdleTimeout: 5 * time.Second, } log.Println(fmt.Sprintf("Serving HTTP requests on %s ", address)) select { case <-ctx.Done(): s.Close() default: log.Fatal(s.ListenAndServe().Error()) } }, } )
Functions ¶
Types ¶
type Config ¶
type Config struct { Redirects string `name:"redirects" short:"r" description:"remote URL or local path to vanity redirects as yml"` HTTPAddress string `name:"http-address" short:"a" description:"host:port for the http server"` Debug bool `name:"debug" short:"d" description:"print detailed logs for errors"` NoOfSubPaths int `name:"no-of-subpaths" short:"n" description:"number of subpaths"` }
Config represents the configuration
Click to show internal directories.
Click to hide internal directories.