ARTICLE AD BOX
Hi I am trying to generate go code by using the oapi-codegen toolkit. My openapi spec 3.0.3 is pretty extensive. The generation of the code (with strict http setting) is flawless but it results in a massive file obviously.
I would like to have a startable skeleton server before I start working on it but I need a main.go (for gorillamux). I found one (listed here) that comes pretty close but it has a api.NewServer() call that fails because the main.go file doesnt work in my context. Does anyone has experience with the type of code generated (I used the latest version) and what needs to be done to start it? The file is copied (with some minimal changes) from "https://github.com/oapi-codegen/oapi-codegen/blob/main/examples/minimal-server/gorillamux/main.go"
package main import ( "log" "net/http" "oinregister/api" "github.com/gorilla/mux" ) func main() { // create a type that satisfies the `api.ServerInterface`, which contains an implementation of every operation from the generated code server := api.NewServer() r := mux.NewRouter() // get an `http.Handler` that we can use h := api.HandlerFromMux(server, r) s := &http.Server{ Handler: h, Addr: "0.0.0.0:8080", } // And we serve HTTP until the world ends. log.Fatal(s.ListenAndServe()) }Thanks
Peter
