github.com/emreu/go-swagger@v0.22.1/examples/task-tracker/cmd/task-tracker-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/task-tracker/restapi"
    11  	"github.com/go-swagger/go-swagger/examples/task-tracker/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.NewTaskTrackerAPI(swaggerSpec)
    26  	server := restapi.NewServer(api)
    27  	defer server.Shutdown()
    28  
    29  	parser := flags.NewParser(server, flags.Default)
    30  	parser.ShortDescription = "Issue Tracker API"
    31  	parser.LongDescription = "This application implements a very simple issue tracker.\nIt's implemented as an API which is described by this swagger spec document.\n\nThe go-swagger project uses this specification to test the code generation.\nThis document contains all possible values for a swagger definition.\nThis means that it exercises the framework relatively well.\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  }