oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

docs(FAQ): "how can I use an unsupported, but `net/http` compliant library?"

Open jamietanna opened this issue 1 year ago • 0 comments

package main

import (
	"log"
	"net/http"

	"github.com/deepmap/oapi-codegen/v2/examples/minimal-server/gorillamux/api"
)

func main() {
	// create a type that satisfies the `api.ServerInterface`, which contains an implementation of every operation from the generated code
	server := api.NewServer()

	// get an `http.Handler` that we can use, but don't specify the router
	h := api.Handler(server)

	s := &http.Server{
		Handler: h,
		Addr:    "0.0.0.0:8080",
	}

	// And we serve HTTP until the world ends.
	log.Fatal(s.ListenAndServe())
}

jamietanna avatar Apr 20 '24 16:04 jamietanna