github.com/djarvur/go-swagger@v0.18.0/examples/composed-auth/cmd/multi-auth-example-server/main.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package main 4 5 import ( 6 "log" 7 "os" 8 9 loads "github.com/go-openapi/loads" 10 "github.com/go-swagger/go-swagger/examples/composed-auth/restapi" 11 "github.com/go-swagger/go-swagger/examples/composed-auth/restapi/operations" 12 flags "github.com/jessevdk/go-flags" 13 ) 14 15 // This file was generated by the swagger tool. 16 // Make sure not to overwrite this file after you generated it because all your edits would be lost! 17 18 func main() { 19 20 swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON) 21 if err != nil { 22 log.Fatalln(err) 23 } 24 25 api := operations.NewMultiAuthExampleAPI(swaggerSpec) 26 server := restapi.NewServer(api) 27 defer server.Shutdown() 28 29 parser := flags.NewParser(server, flags.Default) 30 parser.ShortDescription = "Composing authorizations" 31 parser.LongDescription = "This sample API demonstrates how to compose several authentication schemes\nand configure complex security requirements for your operations.\n\nThis API simulates a very simple market place with customers and resellers\nof items.\n\nPersonas:\n - as a first time user, I want to see all items on sales\n - as a registered customer, I want to post orders for items and\n consult my past orders\n - as a registered reseller, I want to see all pending orders on the items\n I am selling on the market place\n - as a reseller managing my own inventories, I want to post replenishment orders for the items I provide\n - as a register user, I want to consult my personal account infos\n\nThe situation we defined on the authentication side is as follows:\n - every known user is authenticated using a basic token\n - resellers are authenticated using API keys - we let the option to authenticate using a header or query param\n - any registered user (customer or reseller) will add a signed JWT to access more API endpoints\n\nObviously, there are several ways to achieve the same result. We just wanted to demonstrate here how\nsecurity requirements may compose several schemes.\n\nNote that we used the \"OAuth2\" declaration here but don't implement a real\nOAuth2 workflow: our intend here is just to be able to extract scopes from a passed JWT token (the\nonly way to manipulate scoped authorizers with Swagger 2.0 is to declare them with type \"oauth2\").\n" 32 33 server.ConfigureFlags() 34 for _, optsGroup := range api.CommandLineOptionsGroups { 35 _, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options) 36 if err != nil { 37 log.Fatalln(err) 38 } 39 } 40 41 if _, err := parser.Parse(); err != nil { 42 code := 1 43 if fe, ok := err.(*flags.Error); ok { 44 if fe.Type == flags.ErrHelp { 45 code = 0 46 } 47 } 48 os.Exit(code) 49 } 50 51 server.ConfigureAPI() 52 53 if err := server.Serve(); err != nil { 54 log.Fatalln(err) 55 } 56 57 }