cmd

package
v0.0.0-...-6162916 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiErrorCode_internal = iota + 1
	ApiErrorCode_passwordGuessing
	ApiErrorCode_parsingRequestBody
	ApiErrorCode_noIdentifiersForUser

	ApiErrorCode_permissions // 5
	ApiErrorCode_invalidInputField
	ApiErrorCode_emailExistsAlready
	ApiErrorCode_endpointDoesNotExist
	ApiErrorCode_jsonMarshal

	ApiErrorCode_panicRecovery // 10
	ApiErrorCode_missingUser
	ApiErrorCode_dbError
	ApiErrorCode_invalidUrlParam
	ApiErrorCode_thirdPartyRequest

	ApiErrorCode_missingFromContext // 15
	ApiErrorCode_range
)
View Source
const API_ver = "0.1.0" // major version for all related builds
View Source
const ContextTimeout = 50 // number of seconds a single task/context should be allowed to run, we use this with shutting down as well

Variables

View Source
var CFG struct {
	Port               string
	ApiUrl, WebsiteUrl models.ApiString
	ProductionLevel    models.ProductionLevel
	Version, LocalRun  bool
	Cockroach          struct {
		IP, Database, User string
		Port               int
	}
	Redis struct {
		IPs  []string
		Port int
	}
	Slack   toolz.SlackConfig_t
	Mailgun toolz.MailgunConfig_t
}

global config object

Functions

func ConnectCockroach

func ConnectCockroach(ip string, port int, database, user string) (*sql.DB, error)

func ConnectRedis

func ConnectRedis(ip string, port int) (*radix.Pool, error)

func CreateLoggers

func CreateLoggers() (errorLog, infoLog *log.Logger)

func MonitorSignals

func MonitorSignals(running *bool, srv *http.Server)

! \brief Handles marking the server as shutting down based on a cancel call

func ParseConfig

func ParseConfig() error

Types

type ApiError_t

type ApiError_t struct {
	Error struct {
		Msg  string
		Code int
	}
}

! Basic response object that we send back when there's nothing else to be said

type App_c

type App_c struct {
	InfoLog, ErrorLog *log.Logger
	Running           bool
	WG                *sync.WaitGroup

	ApiRequests *prometheus.CounterVec
	Redis       *redis.DB_c
	Cache       *cache.Cache
	TaskQue     chan *models.Que_t

	Users cockroach.User_c
}

----- HANDLER

func (*App_c) ApiChain

func (this *App_c) ApiChain() alice.Chain

! \brief Re-used default starting point for any api endpoint

func (*App_c) Ddos

func (this *App_c) Ddos(next http.Handler) http.Handler

! \brief Monitors the ip address of the requester and returns an error if they've had too many requests

func (*App_c) ErrorWithMsg

func (this *App_c) ErrorWithMsg(err error, w http.ResponseWriter, httpStatus, code int, msg string, params ...interface{})

! \brief Main error handling function, doesn't do anything with the transaction, but handles the error response object

func (*App_c) Forbidden

func (this *App_c) Forbidden(w http.ResponseWriter, msg string, params ...interface{})

func (*App_c) GetUser

func (this *App_c) GetUser(userID models.UUID) (*models.User_t, error)

! \brief Wrapper around getting a value from the database and saving it in local cache

func (*App_c) MissingParam

func (this *App_c) MissingParam(w http.ResponseWriter, msg string, params ...interface{})

! \brief I seemed to be calling this a lot, so i put a wrapper around missing/bad url and query params

func (*App_c) ParseFromBody

func (this *App_c) ParseFromBody(ctx context.Context, out interface{}) error

! \brief Handles pulling in data from our body into whatever object we need to read it into

func (*App_c) RandError

func (this *App_c) RandError() string

func (*App_c) Respond

func (this *App_c) Respond(err error, w http.ResponseWriter, success interface{})

! \brief When we had an issue that may have been caused by user input, this decides which error should be returned to the user

func (*App_c) Routes

func (this *App_c) Routes() *mux.Router

func (*App_c) ServerError

func (this *App_c) ServerError(err error, code int, w http.ResponseWriter)

The serverError helper writes an error message and stack trace to the errorLog, then sends a generic 500 Internal Server Error response to the user.

func (*App_c) StackRecord

func (this *App_c) StackRecord(msg string, params ...interface{})

! \brief Wrapper around stacktrace so we don't have to create the error each time

func (*App_c) StackTrace

func (this *App_c) StackTrace(err error)

! \brief Pulls out the stack trace error info

func (*App_c) StartTaskQue

func (this *App_c) StartTaskQue()

! \brief We have lots of "things" that we need to que for completion in a background process.

These items stay locally in memory for this instance, so it's important it never gets too large and that it completes before
the service terminates

func (*App_c) SuccessWithMsg

func (this *App_c) SuccessWithMsg(w http.ResponseWriter, in interface{})

! \brief Handles a "successful" api call

Commits the transaction log, and writs out our response to the user

func (*App_c) TaskQueEntry

func (this *App_c) TaskQueEntry(ctx context.Context, ch chan error, que *models.Que_t)

! \brief Publically avialable entry point into this shared class

Looks for a que object and handles whatever is thrown at it

type SignupUser_t

type SignupUser_t struct {
	Email, Password, Phone models.ApiString
}

----- SIGNUP -----//

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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