github.com/circl-dev/go-swagger@v0.31.0/examples/auto-configure/implementation/configure_impl.go (about) 1 package implementation 2 3 import ( 4 "crypto/tls" 5 "log" 6 "net/http" 7 8 "github.com/circl-dev/go-swagger/examples/auto-configure/restapi/operations" 9 "github.com/go-openapi/swag" 10 ) 11 12 type ConfigureImpl struct { 13 flags Flags 14 } 15 16 type Flags struct { 17 Example1 string `long:"example1" description:"Sample for showing how to configure cmd-line flags"` 18 Example2 string `long:"example2" description:"Further info at https://github.com/jessevdk/go-flags"` 19 } 20 21 func (i *ConfigureImpl) ConfigureFlags(api *operations.AToDoListApplicationAPI) { 22 api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ 23 { 24 ShortDescription: "Example Flags", 25 LongDescription: "", 26 Options: &i.flags, 27 }, 28 } 29 } 30 31 func (i *ConfigureImpl) ConfigureTLS(tlsConfig *tls.Config) { 32 // Make all necessary changes to the TLS configuration here. 33 } 34 35 func (i *ConfigureImpl) ConfigureServer(s *http.Server, scheme, addr string) { 36 if i.flags.Example1 != "something" { 37 log.Println("example1 argument is not something") 38 } 39 } 40 41 func (i *ConfigureImpl) SetupMiddlewares(handler http.Handler) http.Handler { 42 return handler 43 } 44 45 func (i *ConfigureImpl) SetupGlobalMiddleware(handler http.Handler) http.Handler { 46 return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { 47 log.Printf("Recieved request on path: %v", req.URL.String()) 48 handler.ServeHTTP(w, req) 49 }) 50 } 51 52 func (i *ConfigureImpl) CustomConfigure(api *operations.AToDoListApplicationAPI) { 53 api.Logger = log.Printf 54 api.ServerShutdown = func() { 55 log.Printf("Running ServerShutdown function") 56 } 57 }