github.com/djarvur/go-swagger@v0.18.0/examples/generated/cmd/petstore-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/generated/restapi"
    11  	"github.com/go-swagger/go-swagger/examples/generated/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.NewPetstoreAPI(swaggerSpec)
    26  	server := restapi.NewServer(api)
    27  	defer server.Shutdown()
    28  
    29  	parser := flags.NewParser(server, flags.Default)
    30  	parser.ShortDescription = "Swagger Petstore"
    31  	parser.LongDescription = "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel '#swagger' on irc.freenode.net.\n\nFor this sample, you can use the api key 'special-key' to test the authorization filters\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  }