MCPcopy Create free account
hub / github.com/oapi-codegen/oapi-codegen / NewGinPetServer

Function NewGinPetServer

examples/petstore-expanded/gin/petstore.go:21–47  ·  view source on GitHub ↗
(petStore *api.PetStore, port string)

Source from the content-addressed store, hash-verified

19)
20
21func NewGinPetServer(petStore *api.PetStore, port string) *http.Server {
22 swagger, err := api.GetSpec()
23 if err != nil {
24 fmt.Fprintf(os.Stderr, "Error loading swagger spec\n: %s", err)
25 os.Exit(1)
26 }
27
28 // Clear out the servers array in the swagger spec, that skips validating
29 // that server names match. We don't know how this thing will be run.
30 swagger.Servers = nil
31
32 // This is how you set up a basic gin router
33 r := gin.Default()
34
35 // Use our validation middleware to check all requests against the
36 // OpenAPI schema.
37 r.Use(middleware.OapiRequestValidator(swagger))
38
39 // We now register our petStore above as the handler for the interface
40 api.RegisterHandlers(r, petStore)
41
42 s := &http.Server{
43 Handler: r,
44 Addr: net.JoinHostPort("0.0.0.0", port),
45 }
46 return s
47}
48
49func main() {
50 port := flag.String("port", "8080", "Port for test HTTP server")

Callers 2

mainFunction · 0.85
TestPetStoreFunction · 0.85

Calls 2

GetSpecFunction · 0.92
RegisterHandlersFunction · 0.92

Tested by 1

TestPetStoreFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…