Documentation ¶
Index ¶
- Constants
- func AuthInterceptor(ctx context.Context) (context.Context, error)
- func DateStamp(t time.Time) *timestamppb.Timestamp
- func GRPCHandlerFunc(grpcServer *grpc.Server, muxgw http.Handler) http.Handler
- func GetIPFromContext(ctx context.Context) string
- func GetUAFromContext(ctx context.Context) string
- func NewGateway(ctx context.Context, endpoint string, handlers ...HandlerFromEndpoint) (*runtime.ServeMux, error)
- func ValidateHandler(in proto.Message) error
- type Errors
- type HandlerFromEndpoint
- type Matadate
- type Server
- type ServerOption
- type Userdata
Constants ¶
const (
JWTMetadata = "jwt_meta"
)
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 GetUAFromContext ¶
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 ¶
ValidateHandler validates the given input message.
It takes a proto.Message as input and returns an error.
Types ¶
type HandlerFromEndpoint ¶
type Matadate ¶
type Matadate struct { Userdata // contains filtered or unexported fields }
func NewMatadata ¶
func (*Matadate) GetDeviceID ¶
func (*Matadate) GetUsername ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
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 ¶
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 ¶
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 ¶
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.