Documentation
¶
Index ¶
- Constants
- Variables
- func ConnectCockroach(ip string, port int, database, user string) (*sql.DB, error)
- func ConnectRedis(ip string, port int) (*radix.Pool, error)
- func CreateLoggers() (errorLog, infoLog *log.Logger)
- func MonitorSignals(running *bool, srv *http.Server)
- func ParseConfig() error
- type ApiError_t
- type App_c
- func (this *App_c) ApiChain() alice.Chain
- func (this *App_c) Ddos(next http.Handler) http.Handler
- func (this *App_c) ErrorWithMsg(err error, w http.ResponseWriter, httpStatus, code int, msg string, ...)
- func (this *App_c) Forbidden(w http.ResponseWriter, msg string, params ...interface{})
- func (this *App_c) GetUser(userID models.UUID) (*models.User_t, error)
- func (this *App_c) MissingParam(w http.ResponseWriter, msg string, params ...interface{})
- func (this *App_c) ParseFromBody(ctx context.Context, out interface{}) error
- func (this *App_c) RandError() string
- func (this *App_c) Respond(err error, w http.ResponseWriter, success interface{})
- func (this *App_c) Routes() *mux.Router
- func (this *App_c) ServerError(err error, code int, w http.ResponseWriter)
- func (this *App_c) StackRecord(msg string, params ...interface{})
- func (this *App_c) StackTrace(err error)
- func (this *App_c) StartTaskQue()
- func (this *App_c) SuccessWithMsg(w http.ResponseWriter, in interface{})
- func (this *App_c) TaskQueEntry(ctx context.Context, ch chan error, que *models.Que_t)
- type SignupUser_t
Constants ¶
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 )
const API_ver = "0.1.0" // major version for all related builds
const ContextTimeout = 50 // number of seconds a single task/context should be allowed to run, we use this with shutting down as well
Variables ¶
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 ConnectRedis ¶
func CreateLoggers ¶
func MonitorSignals ¶
! \brief Handles marking the server as shutting down based on a cancel call
func ParseConfig ¶
func ParseConfig() error
Types ¶
type ApiError_t ¶
! 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) Ddos ¶
! \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 ¶
! \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 ¶
! \brief Handles pulling in data from our body into whatever object we need to read it into
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) 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 ¶
! \brief Wrapper around stacktrace so we don't have to create the error each time
func (*App_c) StackTrace ¶
! \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
type SignupUser_t ¶
----- SIGNUP -----//