frame

package module
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: Apache-2.0 Imports: 34 Imported by: 29

README

frame Build Status

A simple bootstrap for quickly starting a simple server based on gocloud framework

development

To run tests start the docker compose file in ./tests then run : go test -json -cover ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticationMiddleware added in v1.0.7

func AuthenticationMiddleware(next http.Handler) http.Handler

AuthenticationMiddleware Simple http middleware function to verify and extract authentication data supplied in a jwt as authorization bearer token

func AuthorizationControlListHasAccess added in v1.0.5

func AuthorizationControlListHasAccess(ctx context.Context, action string, subject string) (error, bool)

func AuthorizationControlListWrite added in v1.0.5

func AuthorizationControlListWrite(ctx context.Context, action string, subject string) error

func GetEnv

func GetEnv(key, fallback string) string

GetEnv Obtains the environment key or returns the default value

func GetIp

func GetIp(r *http.Request) string

func GetLocalIP

func GetLocalIP() string

func GetMacAddress

func GetMacAddress() string

func StreamAuthInterceptor added in v1.0.7

func StreamAuthInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error

StreamAuthInterceptor An authentication claims extractor that will always verify the information flowing in the streams as true jwt claims

func TenantPartition added in v1.0.7

func TenantPartition(ctx context.Context) func(db *gorm.DB) *gorm.DB

func ToContext

func ToContext(ctx context.Context, service *Service) context.Context

func UnaryAuthInterceptor added in v1.0.7

func UnaryAuthInterceptor(ctx context.Context, req interface{},
	info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

UnaryAuthInterceptor Simple grpc interceptor to extract the jwt supplied via authorization bearer token and verify the authentication claims in the token

Types

type AuthenticationClaims added in v1.0.7

type AuthenticationClaims struct {
	ProfileID      string `json:"profile_id,omitempty"`
	TenantID       string `json:"tenant_id,omitempty"`
	PartitionID    string `json:"partition_id,omitempty"`
	SubscriptionID string `json:"subscription_id,omitempty"`
	jwt.StandardClaims
}

AuthenticationClaims Create a struct that will be encoded to a JWT. We add jwt.StandardClaims as an embedded type, to provide fields like expiry time

func ClaimsFromContext added in v1.0.7

func ClaimsFromContext(ctx context.Context) *AuthenticationClaims

ClaimsFromContext extracts authentication claims from the supplied context if any exist

func (*AuthenticationClaims) AsMetadata added in v1.0.7

func (a *AuthenticationClaims) AsMetadata() map[string]string

AsMetadata Creates a string map to be used as metadata in queue data

func (*AuthenticationClaims) ClaimsToContext added in v1.0.7

func (a *AuthenticationClaims) ClaimsToContext(ctx context.Context) context.Context

ClaimsToContext adds authentication claims to the current supplied context

type BaseModel

type BaseModel struct {
	ID          string `gorm:"type:varchar(50);primary_key"`
	CreatedAt   time.Time
	ModifiedAt  time.Time
	Version     uint32         `gorm:"DEFAULT 0"`
	TenantID    string         `gorm:"type:varchar(50);"`
	PartitionID string         `gorm:"type:varchar(50);"`
	DeletedAt   gorm.DeletedAt `sql:"index"`
}

BaseModel Our simple table holding all the migration data

func (*BaseModel) BeforeCreate

func (model *BaseModel) BeforeCreate(db *gorm.DB) error

BeforeCreate Ensures we update a migrations time stamps

func (*BaseModel) BeforeUpdate

func (model *BaseModel) BeforeUpdate(db *gorm.DB) error

BeforeUpdate Updates time stamp every time we update status of a migration

func (*BaseModel) GetID

func (model *BaseModel) GetID() string

type BaseModelI

type BaseModelI interface {
	GetID() string
}

type Migration

type Migration struct {
	BaseModel

	Name      string `gorm:"type:varchar(50);unique_index"`
	Patch     string `gorm:"type:text"`
	AppliedAt sql.NullTime
}

Migration Our simple table holding all the migration data

type Option

type Option func(service *Service)

func Datastore

func Datastore(ctx context.Context, postgresqlConnection string, readOnly bool) Option

func GrpcServer

func GrpcServer(grpcServer *grpc.Server) Option

func HttpHandler

func HttpHandler(h http.Handler) Option

func HttpOptions

func HttpOptions(httpOpts *server.Options) Option

func RegisterPublisher

func RegisterPublisher(reference string, queueUrl string) Option

func RegisterSubscriber

func RegisterSubscriber(reference string, queueUrl string, concurrency int,
	handler SubscribeWorker) Option

func ServerListener

func ServerListener(listener net.Listener) Option

func Translations added in v1.0.5

func Translations(translationsFolder string, languages ...string) Option

type Queue

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

type Service

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

func FromContext

func FromContext(ctx context.Context) *Service

func NewService

func NewService(name string, opts ...Option) *Service

func (*Service) AddCleanupMethod

func (s *Service) AddCleanupMethod(f func())

func (*Service) AddHealthCheck

func (s *Service) AddHealthCheck(checker health.Checker)

func (*Service) Bundle added in v1.0.6

func (s *Service) Bundle() *i18n.Bundle

func (*Service) DB

func (s *Service) DB(ctx context.Context, readOnly bool) *gorm.DB

func (*Service) Init added in v1.0.4

func (s *Service) Init(opts ...Option)

func (*Service) MigrateDatastore

func (s *Service) MigrateDatastore(ctx context.Context, migrationsDirPath string, migrations ...interface{}) error

MigrateDatastore finds missing migrations and records them in the database

func (Service) Publish

func (s Service) Publish(ctx context.Context, reference string, message []byte, metadata map[string]string) error

func (Service) QID

func (s Service) QID(ctx context.Context, payload []byte) (string, error)

func (Service) QObject

func (s Service) QObject(ctx context.Context, model BaseModelI) ([]byte, map[string]string, error)

func (*Service) Run

func (s *Service) Run(ctx context.Context, address string) error

func (*Service) Stop

func (s *Service) Stop()

type SubscribeWorker

type SubscribeWorker interface {
	Handle(ctx context.Context, message []byte, metadata map[string]string) error
}

Jump to

Keyboard shortcuts

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