github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/todo-list-strict/cmd/todo-list-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  	"github.com/thetreep/go-swagger/examples/todo-list-strict/restapi"
    12  	"github.com/thetreep/go-swagger/examples/todo-list-strict/restapi/operations"
    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.NewTodoListAPI(swaggerSpec)
    26  	server := restapi.NewServer(api)
    27  	defer server.Shutdown()
    28  
    29  	parser := flags.NewParser(server, flags.Default)
    30  	parser.ShortDescription = "Simple To Do List API"
    31  	parser.LongDescription = "This is a simple todo list API\nillustrating go-swagger codegen\ncapabilities.\n"
    32  	server.ConfigureFlags()
    33  	for _, optsGroup := range api.CommandLineOptionsGroups {
    34  		_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
    35  		if err != nil {
    36  			log.Fatalln(err)
    37  		}
    38  	}
    39  
    40  	if _, err := parser.Parse(); err != nil {
    41  		code := 1
    42  		if fe, ok := err.(*flags.Error); ok {
    43  			if fe.Type == flags.ErrHelp {
    44  				code = 0
    45  			}
    46  		}
    47  		os.Exit(code)
    48  	}
    49  
    50  	server.ConfigureAPI()
    51  
    52  	if err := server.Serve(); err != nil {
    53  		log.Fatalln(err)
    54  	}
    55  
    56  }