Skip to content

Generating Go code for the API server #30

Description

@ernesto-jimenez

schematic works nicely when creating a client.

I think it might be cool to consider generating code for the server too.

The bare minimum would be generating the response structs to serialize responses.

A more ambitious goal would be to generate the main boilerplate to serve the HTTP API: http handlers, helpers to parse requests and render responses, etc.

Maybe even doing something like this:

package main

import (
  "http"
  "github.com/whatever/api/server"
)

func main() {
  // NewHandler takes an object that implements server.Handler and returns an http.Handler
  // server.Handler is generated by schematic and it has one method for each link in the Schema
  h := server.NewHandler(backend{})
  s := &http.Server{Addr: ":8080", Handler: h}
  s.ListenAndServe()
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions