Skip to content
Snippets Groups Projects
server.go 2.26 KiB
Newer Older
  • Learn to ignore specific revisions
  • Manuel Kieweg's avatar
    Manuel Kieweg committed
    package main
    
    import (
    	"code.fbi.h-da.de/cocsn/gosdn/restconf/api/server"
    	"code.fbi.h-da.de/cocsn/gosdn/restconf/api/server/operations/ciena_waveserver_interfaces"
    	"code.fbi.h-da.de/cocsn/gosdn/restconf/bin/server/handler"
    	"log"
    	"os"
    
    	"code.fbi.h-da.de/cocsn/gosdn/restconf/api/server/operations"
    	"github.com/go-openapi/loads"
    	flags "github.com/jessevdk/go-flags"
    )
    
    func main() {
    
    	swaggerSpec, err := loads.Embedded(server.SwaggerJSON, server.FlatSwaggerJSON)
    	if err != nil {
    		log.Fatalln(err)
    	}
    
    	api := operations.NewWaveserverRESTAPISwaggerDescriptionAPI(swaggerSpec)
    
    	api.CienaWaveserverInterfacesGetDataWaveserverInterfacesHandler =
    		ciena_waveserver_interfaces.GetDataWaveserverInterfacesHandlerFunc(handler.Ifh)
    
    	api.CienaWaveserverInterfacesGetDataWaveserverInterfacesLogicalInterfaceHandler =
    		ciena_waveserver_interfaces.GetDataWaveserverInterfacesLogicalInterfaceHandlerFunc(handler.Lifh)
    	srv := server.NewServer(api)
    	defer srv.Shutdown()
    
    	parser := flags.NewParser(srv, flags.Default)
    	parser.ShortDescription = "Waveserver REST API Swagger description"
    	parser.LongDescription = "\n# Welcome to the Waveserver REST API swagger interface.\n\nThis page documents the HTTPS actions supported for the objects defined in the Waveserver YANG models.\n\nSelecting a module will expand its contents and show the supported actions.\n\nEach action has a schema associated with it to help show the supported output and required input for the action.  It is also possible to test out the API by filling in the required parameters and clicking the \"Try it out!\" button.\n\nNote that PATCH, POST or DELETE calls will alter the device database from its original state! \n\nFor GET request, all YANG models are wrapped in a <data> element or \"data\" object for XML or JSON content type, respectively.\n      "
    	srv.ConfigureFlags()
    	for _, optsGroup := range api.CommandLineOptionsGroups {
    		_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
    		if err != nil {
    			log.Fatalln(err)
    		}
    	}
    
    	if _, err := parser.Parse(); err != nil {
    		code := 1
    		if fe, ok := err.(*flags.Error); ok {
    			if fe.Type == flags.ErrHelp {
    				code = 0
    			}
    		}
    		os.Exit(code)
    	}
    
    	srv.ConfigureAPI()
    
    	if err := srv.Serve(); err != nil {
    		log.Fatalln(err)
    	}
    
    }