Giter VIP home page Giter VIP logo

go-swagger-tools's Introduction

Go Swagger Tools

This repository contains some tools to make integrating Swagger with Go services more straight-forward. Specifically, it has a utility for generating swagger specifications and HTTP middleware for serving the spec + human-readable documentation.

Generating Swagger Specifications

This repository contains a helper, mkswagger, which generates swagger.json and bindata.go file based on swagger comment docs.

This can be installed via go get:

$ go get github.com/lob/go-swagger-tools/cmds/mkswagger

Once installed it can be used with a //go:generate comment:

//go:generate mkswagger -i github.com/lob/tracking-api/cmd/serve
package swagger

This will generate swagger.json and bindata.go in the same directory and package as its invocation (in this example the swagger package). The specification will be generating by loading the input packge (-i) and walking the source tree.

Invoke mkswagger -help for a complete description of options.

HTTP Middleware

This package includes WithSwagger middleware which can be used to serve the generated Swagger specification and HTML documentation with your service. This is stock net/http middleware which takes a SwaggerOpts struct and a handler to wrap. By default it serves the specification at /swagger.json and the docs as /docs.

For example,

srv := &http.Server{
		Addr: fmt.Sprintf(":%d", app.Config.ServerPort),
		Handler: swagger.WithSwagger(swagger.SwaggerOpts{
			SwaggerSpec: swaggerJSON,
			Title:       "Tracking API",
		}, e),
    }

Run godoc github.com/lob/go-swagger-tools for full documentation.

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.