Giter Site home page Giter Site logo

goat's Introduction

goat

self documenting web framework for Go

Why goat?

I was mesmerized by ASP.NET Core's ability to automatically generate Swagger specs, manage query/body/path params automatically, but I didn't want to cheat on Go by using C#, which I personally don't like writing, so here we are.

How does it work?

Every route is a value of the goat.Route struct. The struct contains everything that goat needs to serve on that route, build the params on demand and document itself using Swagger/OpenAPI. Under the hood it uses net/http to serve and swagno to generate the documentation. Most of the reflection is done at "startup-time", while the "request-time" reflection is minimal.

Usage (draft)

package main

type HelloBody struct {
	Title string `json:"title"`
}

type HelloParams struct {
	Name string // by default, will get name from the query parameters
	Surname string `goat:"surname,path"` // if you want to get it from the path, you need to specify it with a struct tag
	HelloBody // Struct embedding works great here. This will be parsed as JSON from the body of the request.
}

helloHandler := goat.Route[HelloParams, string] {
	Route: "/{surname}",
	Method: http.MethodGET,
	Description: "Greets someone",
	Params: HelloParams {},
	ParamsDescriptions: {
		"Name": "Name of the person to greet",
	},
	Handler: func (c *goat.Context[HelloParams]) (goat.Response[string], error) {
		return goat.NewResponse(200, fmt.Sprintf("Hello, %s %s!", c.Params.Title, c.Params.Name)), nil
	}
}

func main() {
	s := goat.NewServer()
	s.AddHandler(helloHandler)
	s.AddSwagger("/swagger")
	s.Serve(":8080")
}

goat's People

Contributors

tesohh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.