jgoweb

package module
v0.0.0-...-a9959a4 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 40 Imported by: 1

README

jgoweb

James's go web lib

New Project

mkdir <new_project>
-- copy https://github.com/jschneider98/jgotemplate into new project dir
make run
-- localhost:1718/index
-- init go module
go mod init example.com/hello

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertResponse

func AssertResponse(t *testing.T, rr *httptest.ResponseRecorder, code int)

func CallerInfo

func CallerInfo() string

Return's the caller's caller info.

func ClusterAddShard

func ClusterAddShard(ctx ContextInterface, shardName string) error

func ClusterAddShardMap

func ClusterAddShardMap(ctx ContextInterface, shardId string, domain string, accountId string) error

func ClusterDeleteShard

func ClusterDeleteShard(ctx ContextInterface, shardName string) error

func ClusterGetAccounts

func ClusterGetAccounts(ctx ContextInterface) (map[string][]Account, error)

Get account data for all DBs

func ClusterGetShards

func ClusterGetShards(ctx ContextInterface) (map[string][]Shard, error)

Get shard data for all DBs

func ClusterUndeleteShard

func ClusterUndeleteShard(ctx ContextInterface, shardName string) error

func CreateAccount

func CreateAccount(ctx ContextInterface, shardName string, domain string) error

func GetAppConfig

func GetAppConfig() *config.Config

func GetConfigEnvVar

func GetConfigEnvVar() string

func GetConfigPath

func GetConfigPath() string

func GetDbCollection

func GetDbCollection() *jgoWebDb.Collection

Get DB

func GetDefaultWebRouter

func GetDefaultWebRouter() *web.Router

func GetSessionManager

func GetSessionManager() *scs.Manager

func GetWebServer

func GetWebServer(router *web.Router, host string) *http.Server

func GzipServeContent

func GzipServeContent(w http.ResponseWriter, req *http.Request, name string, modTime time.Time, content io.ReadSeeker)

ServeContent is like http.ServeContent, except it applies gzip compression if compression hasn't already been done (i.e., the "Content-Encoding" header is set). It's aware of GzipByter and NotWorthGzipCompressing interfaces, and uses them to improve performance when the provided content implements them. Otherwise, it applies gzip compression on the fly, if it's found to be beneficial.

func InitConfig

func InitConfig()

Init config

func InitDbCollection

func InitDbCollection()

Init Db

func InitMetrics

func InitMetrics()

Init metrics

func InitMockAccount

func InitMockAccount()

func InitMockCtx

func InitMockCtx()

func InitMockQueueJob

func InitMockQueueJob()

func InitMockShard

func InitMockShard()

func InitMockShardMap

func InitMockShardMap()

func InitMockSystemDbUpdate

func InitMockSystemDbUpdate()

func InitMockUser

func InitMockUser()

func InitSession

func InitSession()

Init session

func NewTestRequest

func NewTestRequest(method, path string, body io.Reader) (*httptest.ResponseRecorder, *http.Request)

Make a testing request (lifted/modified from gocraft/web)

func SetConfigEnvVar

func SetConfigEnvVar(envVar string)

func SetConfigPath

func SetConfigPath(path string)

func Start

func Start(router *web.Router)

func StartAll

func StartAll(router *web.Router)

func StartHealthSink

func StartHealthSink(hostname string)

Start Health Sink

func StartHttpServer

func StartHttpServer(router *web.Router, host string)

func StartHttpsServer

func StartHttpsServer(router *web.Router)

Start a HTTPS server that auto updates SSL certs via ACME

func StaticMiddleware

func StaticMiddleware(path string, option ...StaticOption) func(web.ResponseWriter, *web.Request, web.NextMiddlewareFunc)

StaticMiddleware is the same as StaticMiddlewareFromDir, but accepts a path string for backwards compatibility.

func StaticMiddlewareFromDir

func StaticMiddlewareFromDir(dir http.FileSystem, options ...StaticOption) func(web.ResponseWriter, *web.Request, web.NextMiddlewareFunc)

StaticMiddlewareFromDir returns a middleware that serves static files from the specified http.FileSystem. This middleware is great for development because each file is read from disk each time and no special caching or cache headers are sent.

If a path is requested which maps to a folder with an index.html folder on your filesystem, then that index.html file will be served.

Types

type Account

type Account struct {
	Id        sql.NullString   `json:"Id" validate:"omitempty,uuid"`
	Domain    sql.NullString   `json:"Domain" validate:"required"`
	CreatedAt sql.NullString   `json:"CreatedAt" validate:"omitempty,rfc3339"`
	UpdatedAt sql.NullString   `json:"UpdatedAt" validate:"omitempty,rfc3339"`
	DeletedAt sql.NullString   `json:"DeletedAt" validate:"omitempty,rfc3339"`
	Ctx       ContextInterface `json:"-" validate:"-"`
}

Account

var MockAccount *Account

func FetchAccountByDomain

func FetchAccountByDomain(ctx ContextInterface, domain string) (*Account, error)

func FetchAccountById

func FetchAccountById(ctx ContextInterface, id string) (*Account, error)

Factory Method

func GetAllAccounts

func GetAllAccounts(ctx ContextInterface) ([]Account, error)

func NewAccount

func NewAccount(ctx ContextInterface) (*Account, error)

Empty new model

func NewAccountWithData

func NewAccountWithData(ctx ContextInterface, req *web.Request) (*Account, error)

New model with data

func (*Account) Delete

func (a *Account) Delete() error

Soft delete a record

func (*Account) GetCreatedAt

func (a *Account) GetCreatedAt() string

func (*Account) GetDeletedAt

func (a *Account) GetDeletedAt() string

func (*Account) GetDomain

func (a *Account) GetDomain() string

func (*Account) GetId

func (a *Account) GetId() string

func (*Account) GetUpdatedAt

func (a *Account) GetUpdatedAt() string

func (*Account) Hydrate

func (a *Account) Hydrate(req *web.Request) error

Hydrate the model with data

func (*Account) Insert

func (a *Account) Insert() error

Insert a new record

func (*Account) IsValid

func (a *Account) IsValid() error

Validate the model

func (*Account) ProcessSubmit

func (a *Account) ProcessSubmit(req *web.Request) (string, bool, error)

func (*Account) Save

func (a *Account) Save() error

Insert/Update based on pkey value

func (*Account) SetCreatedAt

func (a *Account) SetCreatedAt(val string)

func (*Account) SetDefaults

func (a *Account) SetDefaults()

Set defaults

func (*Account) SetDeletedAt

func (a *Account) SetDeletedAt(val string)

func (*Account) SetDomain

func (a *Account) SetDomain(val string)

func (*Account) SetId

func (a *Account) SetId(val string)

func (*Account) SetUpdatedAt

func (a *Account) SetUpdatedAt(val string)

func (*Account) Undelete

func (a *Account) Undelete() error

Soft undelete a record

func (*Account) Update

func (a *Account) Update() error

Update a record

type ContextInterface

type ContextInterface interface {
	Begin() (*dbr.Tx, error)
	Commit() error
	Rollback() error
	Select(column ...string) *dbr.SelectBuilder
	SelectBySql(query string, value ...interface{}) *dbr.SelectBuilder
	Prepare(query string) (*sql.Stmt, error)
	InsertBySql(query string, value ...interface{}) *dbr.InsertStmt
	InsertInto(table string) *dbr.InsertStmt
	UpdateBySql(query string, value ...interface{}) *dbr.UpdateStmt
	Update(table string) *dbr.UpdateStmt
	OptionalBegin() (*dbr.Tx, error)
	OptionalRollback(tx *dbr.Tx) error
	OptionalCommit(tx *dbr.Tx) error
	FinishTransaction() error
	DeleteFrom(table string) *dbr.DeleteStmt
	SetUser(user *User)
	SessionGetString(key string) (string, error)
	SessionPutString(rw web.ResponseWriter, key string, value string)
	GetDb() *jgoWebDb.Collection
	GetDbSession() *dbr.Session
	SetDbSession(dbSess *dbr.Session)
	GetValidator() *validator.Validate
	GetTemplate(filename string) (*template.Template, error)
}

type DataValues

type DataValues struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

DataValues

type GzipByter

type GzipByter interface {
	// GzipBytes returns gzip compressed contents of the file.
	GzipBytes() []byte
}

GzipByter is implemented by compressed files for efficient direct access to the internal compressed bytes.

type JobExample

type JobExample struct {
	NumSleeps int

	Done    chan bool
	Checkin chan bool
	// contains filtered or unexported fields
}

func NewJobExample

func NewJobExample() *JobExample

func (*JobExample) GetCheckinChannel

func (j *JobExample) GetCheckinChannel() chan bool

func (*JobExample) GetDoneChannel

func (j *JobExample) GetDoneChannel() chan bool

func (*JobExample) GetError

func (j *JobExample) GetError() error

func (*JobExample) GetStatus

func (j *JobExample) GetStatus() string

func (*JobExample) IsDone

func (j *JobExample) IsDone() bool

func (*JobExample) Quit

func (j *JobExample) Quit()

func (*JobExample) Run

func (j *JobExample) Run() error

type JobFactoryExample

type JobFactoryExample struct{}

func (*JobFactoryExample) New

func (jf *JobFactoryExample) New(ctx ContextInterface, name string, params url.Values) (JobInterface, error)

type JobFactoryInterface

type JobFactoryInterface interface {
	New(ContextInterface, string, url.Values) (JobInterface, error)
}

type JobInterface

type JobInterface interface {
	Run() error
	Quit()
	IsDone() bool
	GetError() error
	GetStatus() string
	GetDoneChannel() chan bool
	GetCheckinChannel() chan bool
}

type JobQueue

type JobQueue struct {
	ProcessInterval int
	SchedJob        *scheduler.Job
	Debug           bool
	Ctx             ContextInterface
	// contains filtered or unexported fields
}

func NewJobQueue

func NewJobQueue(ctx ContextInterface, dataStore JobQueueStoreInterface, factory JobFactoryInterface) (*JobQueue, error)

func (*JobQueue) EnqueueJob

func (jq *JobQueue) EnqueueJob(job *QueueJob) error

Simple wrapper

func (*JobQueue) NewContext

func (jq *JobQueue) NewContext() ContextInterface

func (*JobQueue) ProcessJobs

func (jq *JobQueue) ProcessJobs() error

func (*JobQueue) Run

func (jq *JobQueue) Run() error

func (*JobQueue) Stop

func (jq *JobQueue) Stop()

type JobQueueNativeStore

type JobQueueNativeStore struct {
	Ctx            ContextInterface
	MaxConcurrency uint64
	MaxBatch       uint64
	MaxMem         uint64
}

func NewJobQueueNativeStore

func NewJobQueueNativeStore(ctx ContextInterface) (*JobQueueNativeStore, error)

func (*JobQueueNativeStore) ByteToMb

func (jqs *JobQueueNativeStore) ByteToMb(b uint64) uint64

func (*JobQueueNativeStore) EnqueueJob

func (jqs *JobQueueNativeStore) EnqueueJob(job *QueueJob) error

func (*JobQueueNativeStore) GetNextJobs

func (jqs *JobQueueNativeStore) GetNextJobs() ([]QueueJob, error)

func (*JobQueueNativeStore) GetRunningJobs

func (jqs *JobQueueNativeStore) GetRunningJobs() uint64

func (*JobQueueNativeStore) IsMemExceeded

func (jqs *JobQueueNativeStore) IsMemExceeded() bool

type JobQueueStoreInterface

type JobQueueStoreInterface interface {
	GetNextJobs() ([]QueueJob, error)
	EnqueueJob(*QueueJob) error
}

type NotWorthGzipCompressing

type NotWorthGzipCompressing interface {
	// NotWorthGzipCompressing is a noop. It's implemented in order to indicate
	// the file is not worth gzip compressing.
	NotWorthGzipCompressing()
}

NotWorthGzipCompressing is implemented by files that were determined not to be worth gzip compressing (the file size did not decrease as a result).

type QueryIntBuilder

type QueryIntBuilder struct {
	Query        string
	RawQuery     string
	InvalidQuery string
	// contains filtered or unexported fields
}

func NewQueryIntBuilder

func NewQueryIntBuilder(ctx ContextInterface, rawQuery string) *QueryIntBuilder

func (*QueryIntBuilder) Build

func (b *QueryIntBuilder) Build() (string, error)

@TODO: auto fix invalid query strings? Improve logic like crazy? Beter validation?

func (*QueryIntBuilder) GetOperator

func (b *QueryIntBuilder) GetOperator(rawQuery string) string

func (*QueryIntBuilder) GetQuery

func (b *QueryIntBuilder) GetQuery(rawQuery string) (string, error)

func (*QueryIntBuilder) IsValid

func (b *QueryIntBuilder) IsValid() bool

func (*QueryIntBuilder) Parse

func (b *QueryIntBuilder) Parse() string

type QueueJob

type QueueJob struct {
	Id          sql.NullString   `json:"Id" validate:"omitempty,uuid"`
	AccountId   sql.NullString   `json:"AccountId" validate:"required,uuid"`
	Name        sql.NullString   `json:"Name" validate:"required,min=1,max=255"`
	Description sql.NullString   `json:"Description" validate:"required,min=1,max=255"`
	Priority    sql.NullString   `json:"Priority" validate:"omitempty,int"`
	Data        sql.NullString   `json:"Data" validate:"omitempty"`
	Status      sql.NullString   `json:"Status" validate:"omitempty,min=1,max=255"`
	QueuedAt    sql.NullString   `json:"QueuedAt" validate:"omitempty,rfc3339"`
	StartedAt   sql.NullString   `json:"StartedAt" validate:"omitempty,rfc3339"`
	CheckinAt   sql.NullString   `json:"CheckinAt" validate:"omitempty,rfc3339"`
	EndedAt     sql.NullString   `json:"EndedAt" validate:"omitempty,rfc3339"`
	Error       sql.NullString   `json:"Error" validate:"omitempty"`
	Ctx         ContextInterface `json:"-" validate:"-"`
}

QueueJob

var MockQueueJob *QueueJob

func FetchQueueJobById

func FetchQueueJobById(ctx ContextInterface, id string) (*QueueJob, error)

Factory Method

func NewQueueJob

func NewQueueJob(ctx ContextInterface) (*QueueJob, error)

Empty new model

func NewQueueJobWithData

func NewQueueJobWithData(ctx ContextInterface, req *web.Request) (*QueueJob, error)

New model with data

func (*QueueJob) Checkin

func (qj *QueueJob) Checkin(status string) error

func (*QueueJob) Delete

func (qj *QueueJob) Delete() error

Hard delete a record

func (*QueueJob) End

func (qj *QueueJob) End() error

func (*QueueJob) Fail

func (qj *QueueJob) Fail(err error) error

func (*QueueJob) GetAccountId

func (qj *QueueJob) GetAccountId() string

func (*QueueJob) GetCheckinAt

func (qj *QueueJob) GetCheckinAt() string

func (*QueueJob) GetData

func (qj *QueueJob) GetData() string

func (*QueueJob) GetDataValues

func (qj *QueueJob) GetDataValues() (url.Values, error)

func (*QueueJob) GetDescription

func (qj *QueueJob) GetDescription() string

func (*QueueJob) GetEndedAt

func (qj *QueueJob) GetEndedAt() string

func (*QueueJob) GetError

func (qj *QueueJob) GetError() string

func (*QueueJob) GetId

func (qj *QueueJob) GetId() string

func (*QueueJob) GetName

func (qj *QueueJob) GetName() string

func (*QueueJob) GetPriority

func (qj *QueueJob) GetPriority() string

func (*QueueJob) GetQueuedAt

func (qj *QueueJob) GetQueuedAt() string

func (*QueueJob) GetStartedAt

func (qj *QueueJob) GetStartedAt() string

func (*QueueJob) GetStatus

func (qj *QueueJob) GetStatus() string

func (*QueueJob) Hydrate

func (qj *QueueJob) Hydrate(req *web.Request) error

Hydrate the model with data

func (*QueueJob) Insert

func (qj *QueueJob) Insert() error

Insert a new record

func (*QueueJob) IsValid

func (qj *QueueJob) IsValid() error

Validate the model

func (*QueueJob) ProcessSubmit

func (qj *QueueJob) ProcessSubmit(req *web.Request) (string, bool, error)

func (*QueueJob) Save

func (qj *QueueJob) Save() error

Insert/Update based on pkey value

func (*QueueJob) SetAccountId

func (qj *QueueJob) SetAccountId(val string)

func (*QueueJob) SetCheckinAt

func (qj *QueueJob) SetCheckinAt(val string)

func (*QueueJob) SetData

func (qj *QueueJob) SetData(val string)

func (*QueueJob) SetDefaults

func (qj *QueueJob) SetDefaults()

Set defaults

func (*QueueJob) SetDescription

func (qj *QueueJob) SetDescription(val string)

func (*QueueJob) SetEndedAt

func (qj *QueueJob) SetEndedAt(val string)

func (*QueueJob) SetError

func (qj *QueueJob) SetError(val string)

func (*QueueJob) SetId

func (qj *QueueJob) SetId(val string)

func (*QueueJob) SetName

func (qj *QueueJob) SetName(val string)

func (*QueueJob) SetPriority

func (qj *QueueJob) SetPriority(val string)

func (*QueueJob) SetQueuedAt

func (qj *QueueJob) SetQueuedAt(val string)

func (*QueueJob) SetStartedAt

func (qj *QueueJob) SetStartedAt(val string)

func (*QueueJob) SetStatus

func (qj *QueueJob) SetStatus(val string)

func (*QueueJob) Start

func (qj *QueueJob) Start() error

func (*QueueJob) Update

func (qj *QueueJob) Update() error

Update a record

type SearchParams

type SearchParams struct {
	Query      string
	Limit      uint64
	Offset     uint64
	TableAlias string
	FirstName  string
	LastName   string
	IdField    string
	UrlParams  url.Values
}

func NewSearchParams

func NewSearchParams() *SearchParams

func (*SearchParams) BuildDefaultCondition

func (sp *SearchParams) BuildDefaultCondition() (dbr.Builder, error)

type Shard

type Shard struct {
	Id           sql.NullString   `json:"Id" validate:"omitempty,int"`
	Name         sql.NullString   `json:"Name" validate:"required"`
	AccountCount sql.NullString   `json:"AccountCount" validate:"required,int"`
	CreatedAt    sql.NullString   `json:"CreatedAt" validate:"omitempty,rfc3339"`
	UpdatedAt    sql.NullString   `json:"UpdatedAt" validate:"omitempty,rfc3339"`
	DeletedAt    sql.NullString   `json:"DeletedAt" validate:"omitempty,rfc3339"`
	Ctx          ContextInterface `json:"-" validate:"-"`
}

Shard

var MockShard *Shard

func CreateShardByName

func CreateShardByName(ctx ContextInterface, shardName string) (*Shard, error)

func FetchBestShard

func FetchBestShard(ctx ContextInterface) (*Shard, error)

func FetchShardByAccountId

func FetchShardByAccountId(ctx ContextInterface, accountId string) (*Shard, error)

func FetchShardByDomain

func FetchShardByDomain(ctx ContextInterface, email string) (*Shard, error)

func FetchShardByEmail

func FetchShardByEmail(ctx ContextInterface, email string) (*Shard, error)

func FetchShardById

func FetchShardById(ctx ContextInterface, id string) (*Shard, error)

Factory Method

func FetchShardByName

func FetchShardByName(ctx ContextInterface, shardName string) (*Shard, error)

Does not set db session. Mainly used for logical replication of shards.

func GetAllShards

func GetAllShards(ctx ContextInterface) ([]Shard, error)

func GetShardByAccountId

func GetShardByAccountId(ctx ContextInterface, accountId string) (*Shard, error)

Does not alter web context... These fetches/gets are a bit confusing :/ Be careful

func NewShard

func NewShard(ctx ContextInterface) (*Shard, error)

Empty new model

func NewShardWithData

func NewShardWithData(ctx ContextInterface, req *web.Request) (*Shard, error)

New model with data

func (*Shard) Delete

func (s *Shard) Delete() error

Soft delete a record

func (*Shard) GetAccountCount

func (s *Shard) GetAccountCount() string

func (*Shard) GetCreatedAt

func (s *Shard) GetCreatedAt() string

func (*Shard) GetDeletedAt

func (s *Shard) GetDeletedAt() string

func (*Shard) GetId

func (s *Shard) GetId() string

func (*Shard) GetName

func (s *Shard) GetName() string

func (*Shard) GetUpdatedAt

func (s *Shard) GetUpdatedAt() string

func (*Shard) Hydrate

func (s *Shard) Hydrate(req *web.Request) error

Hydrate the model with data

func (*Shard) Insert

func (s *Shard) Insert() error

Insert a new record

func (*Shard) IsValid

func (s *Shard) IsValid() error

Validate the model

func (*Shard) NewWebContext

func (s *Shard) NewWebContext() (ContextInterface, error)

func (*Shard) ProcessSubmit

func (s *Shard) ProcessSubmit(req *web.Request) (string, bool, error)

func (*Shard) Save

func (s *Shard) Save() error

Insert/Update based on pkey value

func (*Shard) SetAccountCount

func (s *Shard) SetAccountCount(val string)

func (*Shard) SetCreatedAt

func (s *Shard) SetCreatedAt(val string)

func (*Shard) SetDefaults

func (s *Shard) SetDefaults()

Set defaults

func (*Shard) SetDeletedAt

func (s *Shard) SetDeletedAt(val string)

func (*Shard) SetId

func (s *Shard) SetId(val string)

func (*Shard) SetName

func (s *Shard) SetName(val string)

func (*Shard) SetUpdatedAt

func (s *Shard) SetUpdatedAt(val string)

func (*Shard) Undelete

func (s *Shard) Undelete() error

Soft undelete a record

func (*Shard) Update

func (s *Shard) Update() error

Update a record

type ShardMap

type ShardMap struct {
	Id        sql.NullString   `json:"Id" validate:"omitempty,int"`
	ShardId   sql.NullString   `json:"ShardId" validate:"required,int"`
	Domain    sql.NullString   `json:"Domain" validate:"required"`
	AccountId sql.NullString   `json:"AccountId" validate:"required,uuid"`
	CreatedAt sql.NullString   `json:"CreatedAt" validate:"omitempty,rfc3339"`
	UpdatedAt sql.NullString   `json:"UpdatedAt" validate:"omitempty,rfc3339"`
	DeletedAt sql.NullString   `json:"DeletedAt" validate:"omitempty,rfc3339"`
	Ctx       ContextInterface `json:"-" validate:"-"`
}

ShardMap

var MockShardMap *ShardMap

func CreateShardMap

func CreateShardMap(ctx ContextInterface, shardId string, domain string, accountId string) (*ShardMap, error)

func FetchShardMapByAccountId

func FetchShardMapByAccountId(ctx ContextInterface, accountId string) (*ShardMap, error)

Factory Method

func FetchShardMapByDomainAccountId

func FetchShardMapByDomainAccountId(ctx ContextInterface, domain string, accountId string) (*ShardMap, error)

Factory Method

func FetchShardMapById

func FetchShardMapById(ctx ContextInterface, id string) (*ShardMap, error)

Factory Method

func GetAllShardMaps

func GetAllShardMaps(ctx ContextInterface) ([]ShardMap, error)

Ignore "deleted" shards

func NewShardMap

func NewShardMap(ctx ContextInterface) (*ShardMap, error)

Empty new model

func NewShardMapWithData

func NewShardMapWithData(ctx ContextInterface, req *web.Request) (*ShardMap, error)

New model with data

func (*ShardMap) Delete

func (sm *ShardMap) Delete() error

Soft delete a record

func (*ShardMap) GetAccountId

func (sm *ShardMap) GetAccountId() string

func (*ShardMap) GetCreatedAt

func (sm *ShardMap) GetCreatedAt() string

func (*ShardMap) GetDeletedAt

func (sm *ShardMap) GetDeletedAt() string

func (*ShardMap) GetDomain

func (sm *ShardMap) GetDomain() string

func (*ShardMap) GetId

func (sm *ShardMap) GetId() string

func (*ShardMap) GetShardId

func (sm *ShardMap) GetShardId() string

func (*ShardMap) GetUpdatedAt

func (sm *ShardMap) GetUpdatedAt() string

func (*ShardMap) Hydrate

func (sm *ShardMap) Hydrate(req *web.Request) error

Hydrate the model with data

func (*ShardMap) Insert

func (sm *ShardMap) Insert() error

Insert a new record

func (*ShardMap) IsValid

func (sm *ShardMap) IsValid() error

Validate the model

func (*ShardMap) ProcessSubmit

func (sm *ShardMap) ProcessSubmit(req *web.Request) (string, bool, error)

func (*ShardMap) Save

func (sm *ShardMap) Save() error

Insert/Update based on pkey value

func (*ShardMap) SetAccountId

func (sm *ShardMap) SetAccountId(val string)

func (*ShardMap) SetCreatedAt

func (sm *ShardMap) SetCreatedAt(val string)

func (*ShardMap) SetDefaults

func (sm *ShardMap) SetDefaults()

Set defaults

func (*ShardMap) SetDeletedAt

func (sm *ShardMap) SetDeletedAt(val string)

func (*ShardMap) SetDomain

func (sm *ShardMap) SetDomain(val string)

func (*ShardMap) SetId

func (sm *ShardMap) SetId(val string)

func (*ShardMap) SetShardId

func (sm *ShardMap) SetShardId(val string)

func (*ShardMap) SetUpdatedAt

func (sm *ShardMap) SetUpdatedAt(val string)

func (*ShardMap) Undelete

func (sm *ShardMap) Undelete() error

Soft undelete a record

func (*ShardMap) Update

func (sm *ShardMap) Update() error

Update a record

type StaticOption

type StaticOption struct {
	Prefix    string
	IndexFile string
}

StaticOption configures how StaticMiddlewareDir handles url paths and index files for directories. If set, Prefix is removed from the start of the url path before attempting to serve a directory or file. If set, IndexFile is the index file to serve when the url path maps to a directory.

type SystemDbUpdate

type SystemDbUpdate struct {
	ApplyUpdate func(ctx ContextInterface) error `json:"-" validate:"-"`
	Id          sql.NullString                   `json:"Id" validate:"omitempty,int"`
	UpdateName  sql.NullString                   `json:"UpdateName" validate:"required,min=1,max=255"`
	Description sql.NullString                   `json:"Description" validate:"required,min=1,max=255"`
	CreatedAt   sql.NullString                   `json:"CreatedAt" validate:"omitempty,rfc3339"`
	Ctx         ContextInterface                 `json:"-" validate:"-"`
}

SystemDbUpdate

var MockSystemDbUpdate *SystemDbUpdate

func CreateSystemDbUpdateByUpdateName

func CreateSystemDbUpdateByUpdateName(ctx ContextInterface, updateName string) (*SystemDbUpdate, error)

Factory Method

func CreateSystemDbUpdateNoContext

func CreateSystemDbUpdateNoContext(updateName string, desc string) *SystemDbUpdate

Empty new update

func FetchSystemDbUpdateById

func FetchSystemDbUpdateById(ctx ContextInterface, id string) (*SystemDbUpdate, error)

Factory Method

func FetchSystemDbUpdateByUpdateName

func FetchSystemDbUpdateByUpdateName(ctx ContextInterface, updateName string) (*SystemDbUpdate, error)

Factory Method

func NewSystemDbUpdate

func NewSystemDbUpdate(ctx ContextInterface) (*SystemDbUpdate, error)

Empty new model

func NewSystemDbUpdateWithData

func NewSystemDbUpdateWithData(ctx ContextInterface, req *web.Request) (*SystemDbUpdate, error)

New model with data

func (*SystemDbUpdate) Clone

func (*SystemDbUpdate) Delete

func (sdu *SystemDbUpdate) Delete() error

Hard delete a record

func (*SystemDbUpdate) GetCreatedAt

func (sdu *SystemDbUpdate) GetCreatedAt() string

func (*SystemDbUpdate) GetDescription

func (sdu *SystemDbUpdate) GetDescription() string

func (*SystemDbUpdate) GetId

func (sdu *SystemDbUpdate) GetId() string

func (*SystemDbUpdate) GetUpdateName

func (sdu *SystemDbUpdate) GetUpdateName() string

func (*SystemDbUpdate) Hydrate

func (sdu *SystemDbUpdate) Hydrate(req *web.Request) error

Hydrate the model with data

func (*SystemDbUpdate) Insert

func (sdu *SystemDbUpdate) Insert() error

Insert a new record

func (*SystemDbUpdate) IsValid

func (sdu *SystemDbUpdate) IsValid() error

Validate the model

func (*SystemDbUpdate) NeedsToRun

func (sdu *SystemDbUpdate) NeedsToRun() (bool, error)

func (*SystemDbUpdate) ProcessSubmit

func (sdu *SystemDbUpdate) ProcessSubmit(req *web.Request) (string, bool, error)

func (*SystemDbUpdate) Run

func (sdu *SystemDbUpdate) Run() error

func (*SystemDbUpdate) Save

func (sdu *SystemDbUpdate) Save() error

Insert/Update based on pkey value

func (*SystemDbUpdate) SetComplete

func (sdu *SystemDbUpdate) SetComplete() error

func (*SystemDbUpdate) SetContext

func (sdu *SystemDbUpdate) SetContext(ctx ContextInterface)

func (*SystemDbUpdate) SetCreatedAt

func (sdu *SystemDbUpdate) SetCreatedAt(val string)

func (*SystemDbUpdate) SetDefaults

func (sdu *SystemDbUpdate) SetDefaults()

Set defaults

func (*SystemDbUpdate) SetDescription

func (sdu *SystemDbUpdate) SetDescription(val string)

func (*SystemDbUpdate) SetId

func (sdu *SystemDbUpdate) SetId(val string)

func (*SystemDbUpdate) SetUpdateName

func (sdu *SystemDbUpdate) SetUpdateName(val string)

func (*SystemDbUpdate) Update

func (sdu *SystemDbUpdate) Update() error

Update a record

type SystemDbUpdateInterface

type SystemDbUpdateInterface interface {
	NeedsToRun() (bool, error)
	Run() error
	SetContext(ctx ContextInterface)
	SetComplete() error
	GetUpdateName() string
	GetDescription() string
	Clone() SystemDbUpdateInterface
}

type SystemDbUpdater

type SystemDbUpdater struct {
	Db        *jgowebDb.Collection
	DbUpdates []SystemDbUpdateInterface
	DryRun    bool
}

func NewSystemDbUpdater

func NewSystemDbUpdater(db *jgowebDb.Collection, updates []SystemDbUpdateInterface, dryRun bool) *SystemDbUpdater

func (*SystemDbUpdater) GetDbUpdateInfo

func (sdu *SystemDbUpdater) GetDbUpdateInfo() (map[string][]SystemDbUpdateInterface, error)

Get update info for all DBs

func (*SystemDbUpdater) MergeErrors

func (sdu *SystemDbUpdater) MergeErrors(cs ...<-chan error) <-chan error

MergeErrors merges multiple channels of errors. Based on https://blog.golang.org/pipelines. Based on https://medium.com/statuscode/pipeline-patterns-in-go-a37bb3a7e61d

func (*SystemDbUpdater) Run

func (sdu *SystemDbUpdater) Run(update SystemDbUpdateInterface, dbName string) error

func (*SystemDbUpdater) RunAll

func (sdu *SystemDbUpdater) RunAll() error

func (*SystemDbUpdater) RunAllByDbSession

func (sdu *SystemDbUpdater) RunAllByDbSession(dbSess *dbr.Session, dbName string) <-chan error

func (*SystemDbUpdater) SetDebug

func (sdu *SystemDbUpdater) SetDebug(debug bool)

func (*SystemDbUpdater) WaitForPipeline

func (sdu *SystemDbUpdater) WaitForPipeline(errs ...<-chan error) error

WaitForPipeline waits for results from all error channels.

type User

type User struct {
	Id         sql.NullString   `json:"Id" validate:"omitempty,uuid"`
	AccountId  sql.NullString   `json:"AccountId" validate:"required,uuid"`
	RoleId     sql.NullString   `json:"RoleId" validate:"required,int"`
	FirstName  sql.NullString   `json:"FirstName" validate:"required"`
	LastName   sql.NullString   `json:"LastName" validate:"required"`
	Email      sql.NullString   `json:"Email" validate:"required"`
	Password   sql.NullString   `json:"Password" validate:"required,min=1,max=255"`
	CreatedAt  sql.NullString   `json:"CreatedAt" validate:"omitempty,rfc3339"`
	DeletedAt  sql.NullString   `json:"DeletedAt" validate:"omitempty,rfc3339"`
	UpdatedAt  sql.NullString   `json:"UpdatedAt" validate:"omitempty,rfc3339"`
	VerifiedAt sql.NullString   `json:"VerifiedAt" validate:"omitempty,rfc3339"`
	Ctx        ContextInterface `json:"-" validate:"-"`

	CurrentPasswordError string `validate:"errorMsg"`
	UserUniqueError      string `validate:"errorMsg"`
	RawPasswordError     string `validate:"errorMsg"`
	// contains filtered or unexported fields
}

User

var MockUser *User

These aren't true mocks. More like "test" structs

func FetchAllUserByAccountId

func FetchAllUserByAccountId(ctx ContextInterface, accountId string) ([]User, error)

func FetchUserByEmail

func FetchUserByEmail(ctx ContextInterface, email string) (*User, error)

func FetchUserById

func FetchUserById(ctx ContextInterface, id string) (*User, error)

Factory Method

func FetchUserByShardEmail

func FetchUserByShardEmail(ctx ContextInterface, email string) (*User, error)

func NewUser

func NewUser(ctx ContextInterface) (*User, error)

Empty new model

func NewUserWithData

func NewUserWithData(ctx ContextInterface, req *web.Request) (*User, error)

New model with data

func (*User) Authenticate

func (u *User) Authenticate(password string) bool

func (*User) Delete

func (u *User) Delete() error

Soft delete a record

func (*User) EmailPreviouslyVerified

func (u *User) EmailPreviouslyVerified() bool

func (*User) GetAccountId

func (u *User) GetAccountId() string

func (*User) GetCreatedAt

func (u *User) GetCreatedAt() string

func (*User) GetDeletedAt

func (u *User) GetDeletedAt() string

func (*User) GetEmail

func (u *User) GetEmail() string

func (*User) GetFirstName

func (u *User) GetFirstName() string

func (*User) GetId

func (u *User) GetId() string

func (*User) GetLastName

func (u *User) GetLastName() string

func (*User) GetPassword

func (u *User) GetPassword() string

func (*User) GetRoleId

func (u *User) GetRoleId() string

func (*User) GetUpdatedAt

func (u *User) GetUpdatedAt() string

func (*User) GetVerifiedAt

func (u *User) GetVerifiedAt() string

func (*User) Hydrate

func (u *User) Hydrate(req *web.Request) error

Hydrate the model with data

func (*User) Insert

func (u *User) Insert() error

Insert a new record

func (*User) IsValid

func (u *User) IsValid() error

Validate the model

func (*User) ProcessSubmit

func (u *User) ProcessSubmit(req *web.Request) (string, bool, error)

func (*User) Save

func (u *User) Save() error

Insert/Update based on pkey value

func (*User) SetAccountId

func (u *User) SetAccountId(val string)

func (*User) SetCreatedAt

func (u *User) SetCreatedAt(val string)

func (*User) SetDefaults

func (u *User) SetDefaults()

Set defaults

func (*User) SetDeletedAt

func (u *User) SetDeletedAt(val string)

func (*User) SetEmail

func (u *User) SetEmail(val string)

func (*User) SetFirstName

func (u *User) SetFirstName(val string)

func (*User) SetFromSession

func (u *User) SetFromSession() error

set user from session

func (*User) SetId

func (u *User) SetId(val string)

func (*User) SetLastName

func (u *User) SetLastName(val string)

func (*User) SetPassword

func (u *User) SetPassword(password string, verifyPassword string)

func (*User) SetRoleId

func (u *User) SetRoleId(val string)

func (*User) SetUpdatedAt

func (u *User) SetUpdatedAt(val string)

func (*User) SetVerifiedAt

func (u *User) SetVerifiedAt(val string)

func (*User) Undelete

func (u *User) Undelete() error

Soft undelete a record

func (*User) Update

func (u *User) Update() error

Update a record

func (*User) UserShardMapIsValid

func (u *User) UserShardMapIsValid() (bool, string, error)

Make sure user is connected to one account id in the shard_map @TODO: logic needs to be better... should not be able to create a 2nd user with the same email etc.

func (*User) VerifyEmail

func (u *User) VerifyEmail(token string) (bool, error)

type WebContext

type WebContext struct {
	User                *User
	Session             *scs.Session
	Template            *template.Template
	Job                 *health.Job
	Method              string
	StartTime           time.Time
	EndPoint            string
	Validate            *validator.Validate
	Db                  *jgoWebDb.Collection
	DbSess              *dbr.Session
	Tx                  *dbr.Tx
	RollbackTransaction bool
}
var MockCtx *WebContext

func NewContext

func NewContext(db *jgoWebDb.Collection) *WebContext

func (*WebContext) AjaxRequireUser

func (ctx *WebContext) AjaxRequireUser(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

Auth middleware

func (*WebContext) Begin

func (ctx *WebContext) Begin() (*dbr.Tx, error)

func (*WebContext) BeginTransaction

func (ctx *WebContext) BeginTransaction(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

Have the context manage the DB transaction. Typically don't do this. Each model handles it's own transaction, which is much faster/safer than having a single transaction for an entire web request. This middleware is useful for testing routes though.

func (*WebContext) Commit

func (ctx *WebContext) Commit() error

func (*WebContext) DeleteFrom

func (ctx *WebContext) DeleteFrom(table string) *dbr.DeleteStmt

func (*WebContext) FinishTransaction

func (ctx *WebContext) FinishTransaction() error

Complete the DB transaction if the web context is managing it.

func (*WebContext) GetDb

func (ctx *WebContext) GetDb() *jgoWebDb.Collection

func (*WebContext) GetDbSession

func (ctx *WebContext) GetDbSession() *dbr.Session

func (*WebContext) GetTemplate

func (ctx *WebContext) GetTemplate(filename string) (*template.Template, error)

Get Template

func (*WebContext) GetValidator

func (ctx *WebContext) GetValidator() *validator.Validate

func (*WebContext) InitDbSession

func (ctx *WebContext) InitDbSession()

Init Db

func (*WebContext) InsertBySql

func (ctx *WebContext) InsertBySql(query string, value ...interface{}) *dbr.InsertStmt

func (*WebContext) InsertInto

func (ctx *WebContext) InsertInto(table string) *dbr.InsertStmt

func (*WebContext) JobError

func (ctx *WebContext) JobError(errorTitle string, err error, codeList ...string)

health stream job error

func (*WebContext) JobSuccess

func (ctx *WebContext) JobSuccess(codeList ...string)

health stream job success

func (*WebContext) JobWarning

func (ctx *WebContext) JobWarning(title string, err error, codeList ...string)

health stream job warning

func (*WebContext) JsonErrorResponse

func (ctx *WebContext) JsonErrorResponse(rw web.ResponseWriter, code int, err error)

write a JSON error response

func (*WebContext) JsonEventErrorResponse

func (ctx *WebContext) JsonEventErrorResponse(rw web.ResponseWriter, code int, msg string)

write a JSON error response that's consistent with Javascript error events (i.e., {error: {message: "Error msg here"}})

func (*WebContext) JsonOkResponse

func (ctx *WebContext) JsonOkResponse(rw web.ResponseWriter, code int, message string)

write a JSON error response

func (*WebContext) JsonResponse

func (ctx *WebContext) JsonResponse(rw web.ResponseWriter, code int, payload string)

write a JSON response

func (*WebContext) LoadDi

func (ctx *WebContext) LoadDi(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

Various context dependancy injection (DbCollection, metrics, etc)

func (*WebContext) LoadEndPoint

func (ctx *WebContext) LoadEndPoint(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

EndPoint middleware Get endpoint for route (i.e., path = "/search/other/etc", endpoint = "search")

func (*WebContext) LoadJob

func (ctx *WebContext) LoadJob(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

HealthStream job middle ware for routes

func (*WebContext) LoadSession

func (ctx *WebContext) LoadSession(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

Session middleware

func (*WebContext) LoadTemplate

func (ctx *WebContext) LoadTemplate(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

Template middleware

func (*WebContext) OptionalBegin

func (ctx *WebContext) OptionalBegin() (*dbr.Tx, error)

Only start a transaction if one hasn't been started yet

func (*WebContext) OptionalCommit

func (ctx *WebContext) OptionalCommit(tx *dbr.Tx) error

Commit if there's no tx in the context

func (*WebContext) OptionalRollback

func (ctx *WebContext) OptionalRollback(tx *dbr.Tx) error

Rollback if there's no tx in the context

func (*WebContext) Prepare

func (ctx *WebContext) Prepare(query string) (*sql.Stmt, error)

func (*WebContext) RequireUser

func (ctx *WebContext) RequireUser(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

Auth middleware

func (*WebContext) Rollback

func (ctx *WebContext) Rollback() error

func (*WebContext) Select

func (ctx *WebContext) Select(column ...string) *dbr.SelectBuilder

func (*WebContext) SelectBySql

func (ctx *WebContext) SelectBySql(query string, value ...interface{}) *dbr.SelectBuilder

func (*WebContext) SessionGetString

func (ctx *WebContext) SessionGetString(key string) (string, error)

func (*WebContext) SessionPutString

func (ctx *WebContext) SessionPutString(rw web.ResponseWriter, key string, value string)

func (*WebContext) SetDbSession

func (ctx *WebContext) SetDbSession(dbSess *dbr.Session)

func (*WebContext) SetJobSuccessRollback

func (ctx *WebContext) SetJobSuccessRollback(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)

Tell the web context to rollback it's transaction upon Job success This middleware is useful for testing routes.

func (*WebContext) SetUser

func (ctx *WebContext) SetUser(user *User)

func (*WebContext) Update

func (ctx *WebContext) Update(table string) *dbr.UpdateStmt

func (*WebContext) UpdateBySql

func (ctx *WebContext) UpdateBySql(query string, value ...interface{}) *dbr.UpdateStmt

func (*WebContext) UpdateWebMetrics

func (ctx *WebContext) UpdateWebMetrics(code string)

func (*WebContext) Welcome

func (c *WebContext) Welcome(rw web.ResponseWriter, req *web.Request)

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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