backend_utils

package module
v0.0.0-...-4158e05 Latest Latest
Warning

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

Go to latest
Published: May 15, 2018 License: MIT Imports: 33 Imported by: 2

README

backend_utils

A Collection of utility classes

Documentation

Index

Constants

View Source
const (
	PKG_NAME = "RpcClientPool"
	VERSION  = "1.1"
)
View Source
const FATAL_ERROR = "Unrecoverable error."
View Source
const INVALID_REQ = "Invalid request."
View Source
const NOENT = "Did not find entry."

Generic Errors

View Source
const SERIALIZATION_ERROR = "Error while serializing/de-serializing messages."

Variables

View Source
var (
	ErrUnknown = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.Unknown, msg, args...)
	}

	ErrInvalidArg = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.InvalidArgument, msg, args...)
	}

	ErrNotFound = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.NotFound, msg, args...)
	}

	ErrAlreadyExists = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.AlreadyExists, msg, args...)
	}

	ErrResourceExhausted = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.ResourceExhausted, msg, args...)
	}

	ErrPermissionDenied = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.PermissionDenied, msg, args...)
	}

	ErrUnauthenticated = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.Unauthenticated, msg, args...)
	}

	ErrInternal = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.Internal, msg, args...)
	}

	ErrUnimplemented = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.Unimplemented, msg, args...)
	}

	ErrUnavailable = func(msg string, args ...interface{}) error {
		return status.Errorf(codes.Unavailable, msg, args...)
	}
)

Not all of the above errors are implemented. Add them as and when required.

View Source
var (
	ERR_FATAL error = errors.New("Fatal error.")
)

Functions

func BufferStrings

func BufferStrings(args ...string) string

func DefaultRecovery

func DefaultRecovery(arg interface{}) (ret_err error)

func ExternalIP

func ExternalIP() (string, error)

func MyCaller

func MyCaller() string

MyCaller returns the caller of the function that called it :)

func NewEmailSendTask

func NewEmailSendTask(parms taskParams, sender *MailerDaemon) *emailTask

func NewUUID

func NewUUID() (string, error)

NewUUID generates a random UUID according to RFC 4122

func ParseJWTprivKeyFile

func ParseJWTprivKeyFile(file_path string) (*rsa.PrivateKey, error)

func ParseJWTpubKeyFile

func ParseJWTpubKeyFile(file_path string) (*rsa.PublicKey, error)

func RandStringBytes

func RandStringBytes(n int) string

Types

type CDNHostInfo

type CDNHostInfo struct {
	Hostname string `json:"hostname`
	Port     string `json:"port"`
	BaseURL  string `json:"base_url"`
	Protocol string `json:"protocol"`
}

type CmdResult

type CmdResult struct {
	Err    error
	StdOut string
	StdErr string
}

func ExecCommand

func ExecCommand(name string, args ...string) (result *CmdResult)

func (*CmdResult) String

func (c *CmdResult) String() string

type Configurations

type Configurations struct {
	ServerConfig    GrpcServerConfig   `json:"server_config"`
	ClientConfig    []GrpcClientConfig `json:"client_config"`
	PostgresDB      PostgresDBConfig   `json:"postgres_db"`
	DumbDB          DumbDBConfig       `json:"dumb_db"`
	Emailer         EmailerConfig      `json:"emailer"`
	Locker          LockerConfig       `json:"locker_config"`
	FileStoreConfig FsConfig           `json:"fs_config"`
	Proxy           ProxyConfig        `json:"proxy_config"`
	CDNInfo         CDNHostInfo        `json:"cdn_config"`
	Payments        []PaymentProvider  `json:"payment_providers"`
	RedisDB         RedisConfig        `json:"redis_config"`
	// contains filtered or unexported fields
}

func ReadConfFile

func ReadConfFile(file_path string) (*Configurations, error)

func (*Configurations) CreateClientPool

func (c *Configurations) CreateClientPool(heartbeat_map map[string]func(*grpc.ClientConn) error, conn_per_ep int) error

func (*Configurations) GetClientConfig

func (c *Configurations) GetClientConfig(svc_name string) *GrpcClientConfig

func (*Configurations) GetPooledConn

func (c *Configurations) GetPooledConn(svc_name string) *grpc.ClientConn

func (*Configurations) PooledConnDone

func (c *Configurations) PooledConnDone(svc_name string, conn *grpc.ClientConn)

type ConnEndpointInfo

type ConnEndpointInfo struct {
	Tls                bool
	CertFile           string
	ServerHostOverride string
	ServerAddr         string
}

type DumbDBConfig

type DumbDBConfig struct {
	DBName string `json:"db_name"`
	DBPath string `json:"db_path"`
}

type EmailConf

type EmailConf struct {
	Host     string
	Port     int
	UserName string
	Password string
	Auth     smtp.Auth
	Template *template.Template
}

type EmailerConfig

type EmailerConfig struct {
	SmtpAddr string `json:"smtp_addr"`
	SmtpPort int    `json:"smtp_port"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type FsConfig

type FsConfig struct {
	RootPath string `json:"root_path"`
}

type GrpcClientConfig

type GrpcClientConfig struct {
	// Name of the service for which client config is.
	SvcName string `json:"svc_name"`
	// Use TLS for encryption
	UseTls   bool   `json:"use_tls"`
	CertFile string `json:"cert_file"`

	UseJwt bool `json:"use_jwt"`

	ServerHostOverride string `json:"server_host_override"`
	ServerAddr         string `json:"server_addr"`

	// Non-json fields
	JwtToken string
	// contains filtered or unexported fields
}

func (*GrpcClientConfig) CreatePool

func (c *GrpcClientConfig) CreatePool(no_of_conn int, do_heartbeat func(*grpc.ClientConn) error) error

Single client conn pool needs to be synchronized externally.

func (*GrpcClientConfig) GetClientOpts

func (c *GrpcClientConfig) GetClientOpts() ([]grpc.DialOption, error)

func (*GrpcClientConfig) GetPooledConn

func (c *GrpcClientConfig) GetPooledConn() *grpc.ClientConn

func (*GrpcClientConfig) GiveupPooledConn

func (c *GrpcClientConfig) GiveupPooledConn(conn *grpc.ClientConn)

func (*GrpcClientConfig) NewRPCConn

func (c *GrpcClientConfig) NewRPCConn() (*grpc.ClientConn, error)

func (*GrpcClientConfig) WithJWTToken

func (c *GrpcClientConfig) WithJWTToken(token string) *GrpcClientConfig

type GrpcServerConfig

type GrpcServerConfig struct {

	// Use TLS for encryption
	UseTls   bool   `json:"use_tls"`
	CertFile string `json:"cert_file"`
	KeyFile  string `json:"key_file"`

	// Use JWT based authentication
	UseJwt      bool   `json:"use_jwt"`
	PubKeyFile  string `json:"pub_key"`
	PrivKeyFile string `json:"priv_key"`

	UseValidator bool  `json:"use_validator"`
	UseRecovery  bool  `json:"use_recovery"`
	Port         int32 `json:"port"`
	LogLevel     int32 `json:"log_level"`

	// Non-json fields
	PubKey  *rsa.PublicKey
	PrivKey *rsa.PrivateKey
	// contains filtered or unexported fields
}

func (*GrpcServerConfig) DefaultAuthFunction

func (c *GrpcServerConfig) DefaultAuthFunction(ctx context.Context) (context.Context, error)

func (*GrpcServerConfig) GetServerOpts

func (c *GrpcServerConfig) GetServerOpts() ([]grpc.ServerOption, error)

func (*GrpcServerConfig) Valid

func (c *GrpcServerConfig) Valid() bool

func (*GrpcServerConfig) WithAuthFunc

func (c *GrpcServerConfig) WithAuthFunc(auth func(context.Context) (context.Context, error))

func (*GrpcServerConfig) WithRecvFunc

func (c *GrpcServerConfig) WithRecvFunc(recv grpc_recovery.RecoveryHandlerFunc)

type JwtCredentials

type JwtCredentials struct {
	credentials.PerRPCCredentials
	// contains filtered or unexported fields
}

func NewJwtCredentials

func NewJwtCredentials(tok string) *JwtCredentials

func (*JwtCredentials) GetRequestMetadata

func (j *JwtCredentials) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

GetRequestMetadata gets the current request metadata

func (*JwtCredentials) RequireTransportSecurity

func (j *JwtCredentials) RequireTransportSecurity() bool

Jwt does not RequireTransportSecurity

type LockerConfig

type LockerConfig struct {
	Handler string   `json:"handler"`
	Address []string `json:"address"`
}

type LogUtil

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

func InitLogger

func InitLogger(pkgName string, traceLevel int32, use_stdout bool) *LogUtil

func (*LogUtil) AddEmailAlert

func (l *LogUtil) AddEmailAlert(emails []string)

func (*LogUtil) Error

func (l *LogUtil) Error(e error, format string, args ...interface{}) error

func (*LogUtil) FuncEntry

func (l *LogUtil) FuncEntry(format string, args ...interface{})

func (*LogUtil) FuncExit

func (l *LogUtil) FuncExit(format string, args ...interface{})

func (*LogUtil) Info

func (l *LogUtil) Info(format string, args ...interface{})

func (*LogUtil) Panic

func (l *LogUtil) Panic(e error, format string, args ...interface{}) error

type MailerDaemon

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

func NewMailerDaemon

func NewMailerDaemon(host, username, password string, port int) *MailerDaemon

func (*MailerDaemon) SendEmail

func (s *MailerDaemon) SendEmail(to, subject, message string, args ...interface{})

type MailerDaemonType

type MailerDaemonType interface {
	SendEmail(to, subject, message string, args ...interface{})
}

type PaymentProvider

type PaymentProvider struct {
	Provider   string `json:"provider"`
	Secret     string `json:"secret"`
	MerchId    string `json:"merch_id"`
	PublicKey  string `json:"pub_key"`
	PrivateKey string `json:"priv_key"`
}

type PostgresDBConfig

type PostgresDBConfig struct {
	Hostname string `json:"hostname"`
	Port     int    `json:"port"`
	Username string `json:"username"`
	Password string `json:"password"`
	DBName   string `json:"db_name"`
}

func (*PostgresDBConfig) CreatePQDB

func (dbConf *PostgresDBConfig) CreatePQDB() (*sql.DB, error)

func (*PostgresDBConfig) OpenDB

func (dbConf *PostgresDBConfig) OpenDB() (*sql.DB, error)

func (*PostgresDBConfig) RemovePQDB

func (dbConf *PostgresDBConfig) RemovePQDB() error

type ProxyConfig

type ProxyConfig struct {
	Endpoint string `json:"endpoint"`
	Port     string `json:"port"`
}

func (*ProxyConfig) Valid

func (c *ProxyConfig) Valid() bool

type RedisConfig

type RedisConfig struct {
	Hostname string `json:"hostname"`
	Port     int    `json:"port"`
	DBName   string `json:"db_name"`
}

type RpcClientPool

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

func NewRpcClientPool

func NewRpcClientPool(do_heartbeat func(*grpc.ClientConn) error, endpoints []interface{},
	conn_per_ep int, logr_op io.Writer) *RpcClientPool

func (*RpcClientPool) Get

func (r *RpcClientPool) Get() *grpc.ClientConn

func (*RpcClientPool) Put

func (r *RpcClientPool) Put(conn *grpc.ClientConn)

Jump to

Keyboard shortcuts

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