server

package
v0.0.0-...-40a7325 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package server defines a gRPC server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(s *server) error

Option represents an option for a new *server.

func WithBoltDB

func WithBoltDB(path, col string) Option

WithBoltDB receives a path and a colletion to create a BoltDB client and assign it to the new server. If something goes wrong while configuring the client it returns a non-nil error.

func WithHTTPPort

func WithHTTPPort(port string) Option

WithHTTPPort returns an Option to a new Server that assigns to its httpPort field the received port.

func WithInsecureGRPCServer

func WithInsecureGRPCServer() Option

WithInsecureGRPCServer returns an Option to a new Server that assigns to its srv field a insecure gRPC server.

func WithJSONLogger

func WithJSONLogger(out io.Writer) Option

WithJSONLogger returns an Option to a new Server with a JSON based logger.

func WithJWTAuthToken

func WithJWTAuthToken(key string) Option

WithJWTAuthToken returns an Option to a new Server that creates from the received key a JWT that is assigned to the Server.

func WithListener

func WithListener(addr string) Option

WithListener returns an Option to a new Server that assigns to its listener field a TCP listener with the received address.

func WithPostgresDB

func WithPostgresDB(host, port, dbName, table, user, password string, conns int, lifeConns time.Duration) Option

WithPostgresDB receives a set of parameters to create a PostgreSQL client and assign it to the new server. If something goes wrong while configuring the client it returns a non-nil error.

func WithRistrettoCache

func WithRistrettoCache(cap int) Option

WithRistrettoCache returns an Option to a new Server that assigns to its cache a Ristretto's based cache.

func WithSQLiteDB

func WithSQLiteDB(path, table string, conns int, lifeConns time.Duration) Option

WithSQLiteDB receives a set of basic parameters to create a SQLite3 client and assigns it to the new Server. If something goes wrong while configuring the the client it returns a non-nil error.

func WithSecuredGRPCServer

func WithSecuredGRPCServer(crt, key, ca string) Option

WithSecuredGRPCServer returns an Option to a new Server that assigns to its srv field a secured gRPC server with TLS.

func WithTestDB

func WithTestDB() Option

WithTestDB returns an Option to a new server that assigns to its db field an in-memory database for testing.

func WithTextLogger

func WithTextLogger(out io.Writer) Option

WithTextLogger returns an Option to a new Server with a text based logger.

type Server

type Server interface {
	AddCommand(context.Context, *proto.BotCommand) (*empty.Empty, error)
	GetCommand(context.Context, *proto.Command) (*proto.BotCommand, error)
	ListCommands(context.Context, *empty.Empty) (*proto.BotCommands, error)
	UpdateCommand(context.Context, *proto.BotCommand) (*empty.Empty, error)
	DeleteCommand(context.Context, *proto.Command) (*empty.Empty, error)
	Connect() error
	Serve() error
	CloseList()
}

Server represents a gRPC BotioServer with a method to connect to its database.

func New

func New(options ...Option) (Server, error)

New should receive one or more Options to apply then to a new Server that will be return completely initialized.

Jump to

Keyboard shortcuts

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