gateway

package
v0.0.0-...-413143c Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JWTMetadata = "jwt_meta"
)

Variables

This section is empty.

Functions

func AuthInterceptor

func AuthInterceptor(ctx context.Context) (context.Context, error)

func DateStamp

func DateStamp(t time.Time) *timestamppb.Timestamp

DateStamp returns a timestamppb.Timestamp object based on the input time.Time.

It takes a time.Time parameter and returns a *timestamppb.Timestamp object.

func GRPCHandlerFunc

func GRPCHandlerFunc(grpcServer *grpc.Server, muxgw http.Handler) http.Handler

GRPCHandlerFunc generates an http.Handler that can be used to handle gRPC requests and HTTP requests that are not gRPC requests.

It takes in a *grpc.Server and an http.Handler as parameters. The *grpc.Server is used to handle gRPC requests. The http.Handler is used to handle non-gRPC HTTP requests.

The function returns an http.Handler that can be used to handle both gRPC and non-gRPC requests.

func GetIPFromContext

func GetIPFromContext(ctx context.Context) string

func GetUAFromContext

func GetUAFromContext(ctx context.Context) string

func NewGateway

func NewGateway(ctx context.Context, endpoint string, handlers ...HandlerFromEndpoint) (*runtime.ServeMux, error)

NewGateway creates a new v0.server v0.server for handling HTTP requests.

It takes a context.Context, an endpoint string, and one or more HandlerFromEndpoint functions as parameters.

It returns an http.Handler and an error. The http.Handler is the v0.server v0.server that will handle incoming HTTP requests. The error is returned if there are no handlers provided.

func ValidateHandler

func ValidateHandler(in proto.Message) error

ValidateHandler validates the given input message.

It takes a proto.Message as input and returns an error.

Types

type Errors

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

func NewErrors

func NewErrors(msg string, err error) *Errors

func (*Errors) Error

func (e *Errors) Error()

type HandlerFromEndpoint

type HandlerFromEndpoint func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

type Matadate

type Matadate struct {
	Userdata
	// contains filtered or unexported fields
}

func NewMatadata

func NewMatadata(ctx context.Context) *Matadate

func (*Matadate) GetDeviceID

func (md *Matadate) GetDeviceID() (deviceID uint64)

func (*Matadate) GetUserID

func (md *Matadate) GetUserID() (ID uint64)

func (*Matadate) GetUserIP

func (md *Matadate) GetUserIP() (ip string)

func (*Matadate) GetUsername

func (md *Matadate) GetUsername() (username string)

type Server

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

func NewServer

func NewServer(ctx context.Context, gwmux http.Handler, opts ...ServerOption) *Server

NewServer initializes a new v0.server with the provided context, endpoint, gwmux, and options.

ctx: The context.Context to use. endpoint: The endpoint to bind the v0.server to. gwmux: The http.Handler to use. opts: The optional ServerOptions to configure the v0.server. returns: A pointer to the initialized Server.

func (*Server) Server

func (s *Server) Server() *grpc.Server

Server returns the grpc v0.server of the Server struct.

It does not take any parameters. It returns a pointer to the grpc.Server type.

func (*Server) Start

func (s *Server) Start() error

Start starts the v0.server.

It creates an HTTP v0.server with the provided endpoint and v0.server. If mutual TLS is enabled, it sets the TLS configuration. It then runs the v0.server in a separate goroutine. It waits for an interrupt signal to gracefully shut down the v0.server. Finally, it stops the v0.server and returns any error encountered.

Returns: - error: In case of failure to stop the v0.server.

func (*Server) Stop

func (s *Server) Stop(httpSrv *http.Server) error

Stop stops the v0.server and shuts down the HTTP and gRPC servers.

The function takes an `http.Server` as a parameter and returns an error. It first logs a message indicating that the v0.server is being shut down, then stops the gRPC v0.server, logs a message indicating that the gRPC v0.server has been shut down, and then shuts down the HTTP v0.server using the `Shutdown` method of the `http.Server` object passed as a parameter. If an error occurs during the shutdown of the HTTP v0.server, it is returned. Finally, the function logs a message indicating that the HTTP v0.server has been shut down and returns `nil`.

type ServerOption

type ServerOption func(srv *Server)

func WithServerEndpoint

func WithServerEndpoint(endpoint string) ServerOption

WithServerEndpoint sets the v0.server endpoint for the ServerOption.

It takes a string parameter called 'endpoint' which represents the v0.server endpoint.

It returns a ServerOption function that sets the 'endpoint' field of the 'Server' struct.

func WithServerName

func WithServerName(name string) ServerOption

WithServerName sets the name of the v0.server.

Parameters: - name: the name of the v0.server (string). Return type: ServerOption.

type Userdata

type Userdata struct {
	ID       uint64 `json:"id"`
	Username string `json:"username"`
	DeviceID uint64 `json:"device"`
	IP       string `json:"ip"`
}

Jump to

Keyboard shortcuts

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