1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-18 22:17:44 +02:00

api package (#2522)

* api gateway

* add comment
This commit is contained in:
Asim Aslam
2022-07-02 12:11:59 +01:00
committed by GitHub
parent 28298a30e4
commit b6b866c0b2
13 changed files with 320 additions and 138 deletions

View File

@ -1,6 +1,8 @@
// Package api is for building api gateways
package api
import (
"context"
"errors"
"regexp"
"strings"
@ -9,6 +11,8 @@ import (
"go-micro.dev/v4/server"
)
// The Api interface provides a way to
// create composable API gateways
type Api interface {
// Initialise options
Init(...Option) error
@ -18,11 +22,16 @@ type Api interface {
Register(*Endpoint) error
// Register a route
Deregister(*Endpoint) error
// Run the api
Run(context.Context) error
// Implemenation of api
String() string
}
type Options struct{}
type Options struct {
// Address of the server
Address string
}
type Option func(*Options) error
@ -185,3 +194,8 @@ func NewGateway() Gateway {
func WithEndpoint(e *Endpoint) server.HandlerOption {
return server.EndpointMetadata(e.Name, Encode(e))
}
// NewApi returns a new api gateway
func NewApi(opts ...Option) Api {
return newApi(opts...)
}