addressbook

package
v0.0.0-...-8439692 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const ContactMaxPageSize = 10

Variables

View Source
var (
	ErrNotFound   = errors.New("not found")
	ErrBadRequest = errors.New("bad request")
	ErrInternal   = errors.New("internal error")
)

Functions

func CtxGetCorrelationID

func CtxGetCorrelationID(ctx context.Context) string

func CtxGetTenantID

func CtxGetTenantID(ctx context.Context) int64

func CtxSetCorrelationID

func CtxSetCorrelationID(ctx context.Context, value string) context.Context

func CtxSetTenantID

func CtxSetTenantID(ctx context.Context, value int64) context.Context

func DecodeGRPCContactRequest

func DecodeGRPCContactRequest(ctx context.Context, r any) (any, error)

gRPC server method Decode from protobuf to domain object

func DecodeGRPCDeleteContactRequest

func DecodeGRPCDeleteContactRequest(ctx context.Context, r any) (any, error)

gRPC server method Decode from protobuf to domain object

func DecodeGRPCListContactsRequest

func DecodeGRPCListContactsRequest(ctx context.Context, r any) (any, error)

gRPC server method Decode from protobuf to domain object

func DecodeGRPCReadContactRequest

func DecodeGRPCReadContactRequest(ctx context.Context, r any) (any, error)

gRPC server method Decode from protobuf to domain object

func Decrypt

func Decrypt[T any](obj T, privateKey *rsa.PrivateKey) (T, error)

References: https://www.sohamkamani.com/golang/rsa-encryption/#decryption

func DecryptString

func DecryptString(msg string, privateKey *rsa.PrivateKey) (string, error)

func EncodeGRPCContactResponse

func EncodeGRPCContactResponse(ctx context.Context, r any) (any, error)

gRPC server method Encode from domain object to protobuf

func EncodeGRPCListContactsResponse

func EncodeGRPCListContactsResponse(ctx context.Context, r any) (any, error)

gRPC server method Encode from domain object to protobuf

func Encrypt

func Encrypt[T any](obj T, publicKey *rsa.PublicKey) (T, error)

Possible solution for larger message sizes (limit is 190 bytes with 2048 key and SHA256): https://www.nsoftware.com/kb/xml/09051401.rst

func EncryptString

func EncryptString(msg string, publicKey *rsa.PublicKey) (string, error)

func MakeEndpoints

func MakeEndpoints(srv Service) clientapi.Endpoints

func NewGRPCServer

func NewGRPCServer(ctx context.Context, endpoints clientapi.Endpoints) pb.AddressBookServer

func NewHTTPServer

func NewHTTPServer(ctx context.Context, endpoints clientapi.Endpoints) http.Handler

Types

type Contact

type Contact struct {
	ID         int64
	TenantID   int64
	FirstName  string
	LastName   string
	Active     bool
	Address    string
	SomeSecret string
	CreatedAt  string
	UpdatedAt  string
}

type Repository

type Repository interface {
	CreateContact(ctx context.Context, input *clientapi.ContactRequest) (output *clientapi.ContactResponse, err error)
	ReadContact(ctx context.Context, input *clientapi.ReadContactRequest) (output *clientapi.ContactResponse, err error)
	ListContacts(ctx context.Context, input *clientapi.ListContactsRequest) (output *clientapi.ListContactsResponse, err error)
	UpdateContact(ctx context.Context, input *clientapi.ContactRequest) (output *clientapi.ContactResponse, err error)
	DeleteContact(ctx context.Context, input *clientapi.DeleteContactRequest) (output *clientapi.ContactResponse, err error)
}

func NewInMemoryRepository

func NewInMemoryRepository() Repository

type Service

type Service interface {
	CreateContact(ctx context.Context, input *clientapi.ContactRequest) (output *clientapi.ContactResponse, err error)
	ReadContact(ctx context.Context, input *clientapi.ReadContactRequest) (output *clientapi.ContactResponse, err error)
	ListContacts(ctx context.Context, input *clientapi.ListContactsRequest) (output *clientapi.ListContactsResponse, err error)
	UpdateContact(ctx context.Context, input *clientapi.ContactRequest) (output *clientapi.ContactResponse, err error)
	DeleteContact(ctx context.Context, input *clientapi.DeleteContactRequest) (output *clientapi.ContactResponse, err error)
}

type StandardPayloadError

type StandardPayloadError struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message"`
}

type StandardPayloadResponse

type StandardPayloadResponse struct {
	Data          []any                  `json:"data"`
	NextPageToken int64                  `json:"next_page_token"`
	Errors        []StandardPayloadError `json:"errors"`
	CorrelationID string                 `json:"correlation_id"`
}

Jump to

Keyboard shortcuts

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