ginmill

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2022 License: MIT Imports: 1 Imported by: 4

README

Ginmill

Create Gin server with pre-define routes.

It is useful to create compatible endpoint/API set with well-known request patha and focus on implementing gin.Context handlers.

Example

Implement Features from pre-defined routes.

Let your gin server be with the Features


Publish your website interface to be known as Features. Something like:

package mastodon

import (
	"github.com/gin-gonic/gin"
	"github.com/ginmills/ginmill"
)

// IMastodon defines functions must to be done
type IMastodon interface {
	// OAuthAuthorize for GET /oauth/authorize
	OAuthAuthorize(c *gin.Context)
	// OAuthObtainToken for POST /oauth/token
	OAuthObtainToken(c *gin.Context)
	// OAuthRevokeToken for POST /oauth/revoke
	OAuthRevokeToken(c *gin.Context)

}

// Features let you to be a mastodon
func Features(m IMastodon) (features *ginmill.Features) {
	r := gin.New()

	oauth := r.Group("/oauth")

	oauth.GET("/authorize", m.OAuthAuthorize)
	oauth.POST("/token", m.OAuthObtainToken)
	oauth.POST("/revoke", m.OAuthRevokeToken)

	// TODO: add more known api routes

	features = ginmill.NewFeatures(r.Routes())

	return features
}

So that people have ginmills with your features.

Full IMastodon Features can be found here

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Features

type Features struct {
	// contains filtered or unexported fields
}

Features are pre-defined routes

func NewFeatures

func NewFeatures(routes gin.RoutesInfo) *Features

NewFeatures create Features from RoutesInfo

type Ginmill

type Ginmill interface {
	With(f *Features) (err error)
}

Ginmill is an interface intend to describe features of your gin engine

type Server

type Server struct {
	Ginmill
	Engine *gin.Engine
}

Server contains A gin engine and a ginmill

func (*Server) With

func (s *Server) With(f *Features) *Server

With pre-defined Features for ginmill

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL