gateway

package module
v0.0.0-...-263ef06 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

README

Gateway

The nucleo-gateway is the official API gateway service for Nucleo framework. Use it to publish your services

Features

  • support HTTP & HTTPS
  • serve static files
  • multiple routes
  • support Connect-like middlewares in global-level, route-level and alias-level.
  • alias names (with named parameters & REST routes)
  • whitelist
  • multiple body parsers (json, urlencoded). Use our middlewares to set this up
  • CORS headers. Use with our middlewares.
  • Rate limiter. Use custom middleware for this.
  • before & after call hooks
  • Buffer & Stream handling
  • support authentication and authorization

Installation

go get github.com/Bendomey/awesome-nucleo/gateway

Usage

import (
    "github.com/Bendomey/nucleo-go"
    "github.com/Bendomey/awesome-nucleo/gateway"
)

var GatewayMixin = gateway.NewGatewayMixin(gateway.GatewayMixin{})

var ApiService = nucleo.ServiceSchema{
    Name: "api",
    Mixins:  []nucleo.Mixin{GatewayMixin},
    Settings: map[string]interface{}{
        "port": 5001,
    }
}

License

awesome-nucleo is available under the Apache License

Contact

Copyright (c) 2023 Awesome Nucleo

Documentation

Index

Constants

View Source
const (
	LIBRARY_NAME       = "nucleo-gateway"
	LIBRARY_VERSION    = "0.1.0"
	LIBRARY_REPOSITORY = "https://github.com/Bendomey/awesome-gateway"

	MappingPolicyAll      MappingPolicyType = "all"
	MappingPolicyRestrict MappingPolicyType = "restrict"
)

Variables

This section is empty.

Functions

func NewGatewayMixin

func NewGatewayMixin(start GatewayMixin) nucleo.Mixin

Types

type AuthenticateMethodsFunc

type AuthenticateMethodsFunc = func(context nucleo.Context, ginContext *gin.Context, alias string) interface{}

type AuthorizeMethodFunc

type AuthorizeMethodFunc = func(context nucleo.Context, ginContext *gin.Context, alias string)

type GatewayMixin

type GatewayMixin struct {
	Authenticate *AuthenticateMethodsFunc
	Authorize    *AuthorizeMethodFunc
}

type GatewayService

type GatewayService struct {
	Authenticate *AuthenticateMethodsFunc
	Authorize    *AuthorizeMethodFunc
	// contains filtered or unexported fields
}

func (*GatewayService) Created

func (svc *GatewayService) Created(schema nucleo.ServiceSchema, logger *log.Entry)

func (*GatewayService) Dependencies

func (svc *GatewayService) Dependencies() []string

func (*GatewayService) Metadata

func (svc *GatewayService) Metadata() map[string]interface{}

func (GatewayService) Name

func (svc GatewayService) Name() string

func (*GatewayService) Started

func (svc *GatewayService) Started(context nucleo.BrokerContext, schema nucleo.ServiceSchema)

func (*GatewayService) Stopped

func (svc *GatewayService) Stopped(context nucleo.BrokerContext, service nucleo.ServiceSchema)

type MappingPolicyType

type MappingPolicyType string

type Route

type Route struct {
	// Name of the route group
	Name string

	// Path of the route group
	Path string

	// Route-level middlewares.
	Use []gin.HandlerFunc

	//whitelist filter used to filter the list of actions.
	//accept regex, and wildcard on action name
	//regex: /^math\.\w+$/
	//wildcard: posts.*
	Whitelist []string

	//mappingPolicy -> all : include all actions, the ones with aliases and without.
	//mappingPolicy -> restrict : include only actions that are in the list of aliases.
	MappingPolicy MappingPolicyType

	//aliases -> alias names instead of action names.
	Aliases map[string]string

	// This is called before action is called
	OnBeforeCall *func(context nucleo.Context, ginContext *gin.Context, route Route, alias string)

	// This is called after action is called but before response is sent to user.
	OnAfterCall *func(context nucleo.Context, ginContext *gin.Context, route Route, response nucleo.Payload)

	//authorization turn on/off authorization
	Authorization bool

	//authentication turn on/off authentication
	Authentication bool
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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