github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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  	"github.com/go-openapi/loads"
    10  	flags "github.com/jessevdk/go-flags"
    11  
    12  	"github.com/thetreep/go-swagger/examples/generated/restapi"
    13  	"github.com/thetreep/go-swagger/examples/generated/restapi/operations"
    14  )
    15  
    16  // This file was generated by the swagger tool.
    17  // Make sure not to overwrite this file after you generated it because all your edits would be lost!
    18  
    19  func main() {
    20  
    21  	swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
    22  	if err != nil {
    23  		log.Fatalln(err)
    24  	}
    25  
    26  	api := operations.NewPetstoreAPI(swaggerSpec)
    27  	server := restapi.NewServer(api)
    28  	defer server.Shutdown()
    29  
    30  	parser := flags.NewParser(server, flags.Default)
    31  	parser.ShortDescription = "Swagger Petstore"
    32  	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"
    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  }