Giter Site home page Giter Site logo

swaggest / swgui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lazada/swgui

49.0 2.0 8.0 36.92 MB

Embedded Swagger UI for Go

Home Page: https://pkg.go.dev/github.com/swaggest/swgui

License: Apache License 2.0

Go 82.82% Makefile 17.18%
swagger openapi swagger-ui openapi3

swgui's Introduction

Swagger UI

GoDevDoc

Package swgui (Swagger UI) provides HTTP handler to serve Swagger UI. All assets are embedded in Go source code, so just build and run.

V5

Static assets for v5 are built from Swagger UI v5.10.3.

CDN-based v5cdn uses Swagger UI v5.10.3.

V4

Static assets for v4 are built from Swagger UI v4.19.1.

CDN-based v4cdn uses Swagger UI v4.18.3.

V3

Static assets for v3 are built from Swagger UI v3.52.5.

CDN-based v3cdn uses Swagger UI v3.52.4.

How to use

package main

import (
	"net/http"

	"github.com/swaggest/swgui/v5emb"
)

func main() {
	http.Handle("/api1/docs/", v5emb.New(
		"Petstore",
		"https://petstore3.swagger.io/api/v3/openapi.json",
		"/api1/docs/",
	))

	http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		_, _ = writer.Write([]byte("Hello World!"))
	})

	println("docs at http://localhost:8080/api1/docs/")
	_ = http.ListenAndServe("localhost:8080", http.DefaultServeMux)
}

If you use go1.16 or later, you can import natively embedded assets with "github.com/swaggest/swgui/v5emb", it may help to lower application memory usage.

Use CDN for assets

In order to reduce binary size you can import github.com/swaggest/swgui/v3cdn to use CDN hosted assets.

Also you can use swguicdn build tag to enable CDN mode for github.com/swaggest/swgui/v3 import.

Be aware that CDN mode may be considered inappropriate for security or networking reasons.

Documentation viewer CLI tool

Install swgui.

go install github.com/swaggest/swgui/cmd/swgui@latest

Or download binary from releases.

Linux AMD64

wget https://github.com/swaggest/swgui/releases/latest/download/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && rm linux_amd64.tar.gz
./swgui -version

Macos Intel

wget https://github.com/swaggest/swgui/releases/latest/download/darwin_amd64.tar.gz && tar xf darwin_amd64.tar.gz && rm darwin_amd64.tar.gz
codesign -s - ./swgui
./swgui -version

Macos Apple Silicon (M1, etc...)

wget https://github.com/swaggest/swgui/releases/latest/download/darwin_arm64.tar.gz && tar xf darwin_arm64.tar.gz && rm darwin_arm64.tar.gz
codesign -s - ./swgui
./swgui -version

Open spec file.

swgui my-openapi.yaml

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.