Documentation ¶
Index ¶
- Constants
- Variables
- func AddRecordToContext(next http.Handler) http.Handler
- func AddSchemaAndTableToContext(next http.Handler) http.Handler
- func AllOK(oks ...bool) bool
- func AskForConfirmation(s string) bool
- func CreateDefaultConfigFile(configFileName string) error
- func DBErrorCodeToHTTPErrorCode(dbCode pq.ErrorCode) (httpCode int)
- func HyphensToUnderscores(table string) string
- func Log(module string, isOk bool, message string, err error)
- func LogDebug(module string, isOk bool, message string, err error)
- func LogFatal(module string, isOk bool, message string, err error)
- func MapToValsAndCols(r map[string]interface{}) (cols, vals string)
- func RandomString(strlen int) string
- func TestErrorFatal(t *testing.T, description string, got string, expected string)
- type Bundles
- type Query
- type ResponseError
- type WhereConfig
Constants ¶
const ( ContentTypeHTML = `text/html; charset=utf-8` ContentTypeJSON = `application/json; charset=utf-8` ContentTypeJS = `application/javascript` ContentTypeCSS = `text/css` )
const ( SQLToFindUserByEmail = `SELECT id from users WHERE email = '%s';` SQLToGetUsersRole = `SELECT role from users WHERE id = '%s';` //General //NO SEMI COLONS AT THE END SQLToSelectAllFieldsFrom = `SELECT * FROM %s.%s` SQLToSelectWhere = `SELECT * FROM %s.%s WHERE id = '%v'` //depracated SQLToSelectByID = `SELECT * FROM %s.%s WHERE id = '%v'` SQLToSelectWhereXEqualsY = `SELECT * FROM %s.%s WHERE %s = '%v'` SQLToInsertReturningJSON = `INSERT INTO %s.%s(%s) VALUES (%s) returning row_to_json(%s)` SQLToInsertAllDefaultsReturningJSON = `INSERT INTO %s.%s DEFAULT VALUES returning row_to_json(%s)` SQLToDeleteWhere = `DELETE FROM %s.%s WHERE id = '%v'` SQLToUpdateWhereReturningJSON = `UPDATE %s.%s SET (%s) = (%s) WHERE id = '%v' returning row_to_json(%s)` //Full text search_path SQLToFullTextSearch = `` /* 174-byte string literal not displayed */ )
SQl query strings for application-wide use
Variables ¶
var ( SuperUserDBConfig dbConfig ServerUserDBConfig dbConfig )
SuperUserDBConfig is the connection configuration for the super user ServerUserDBConfig is the connection configuration for the 'server' role user
var App application
App is the container for the app-wide constructs like database, router and mailserver
var BeforeServe func()
ActivatePackages is a hook for activating packages from main
var Defaults = config{ PgSuperUser: "postgres", PgDBName: "testdb", PgPort: "5432", PgServer: "localhost", PgDisableSSL: true, ApiPort: "3000", JWTRealm: "Your App Name", Host: "localhost", Protocol: "http", ActivateEmail: false, SmtpHost: "smtp", SmtpPort: "25", SmtpUserName: "info@yourdomain.com", SmtpFrom: "info@yourdomain.com", EmailFrom: "Your Name", BundlesInstalled: make([]string, 0, 0), GlobalMiddleware: []string{"RequestID", "RealIP", "Logger", "Recoverer", "CloseNotify", "Timeout"}, Timeout: 60, ActivateCors: false, CorsAllowedOrigins: []string{"*"}, CorsAllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "SEARCH"}, CorsAllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"}, CorsExposedHeaders: []string{"Link"}, CorsAllowCredentials: true, CorsMaxAge: 300, }
Defaults the the app wide default settings
var ServeCmd = &cobra.Command{
Use: "serve",
Short: "Starts the ghost server",
Long: `Start the ghost API Server`,
RunE: serve,
}
ServeCmd represents the serve command
var TestDBConfig = dbConfig{ // contains filtered or unexported fields }
TestDBConfig is a ready to go database config for testing purposes TODO: at the moment the config for testing is fixed - need to work out clean way of allowing users to specify different config
Functions ¶
func AllOK ¶
AllOK Takes any number of bools and returns true if all are true, or false if ANY are false
func AskForConfirmation ¶
AskForConfirmation asks the user for confirmation. A user must type in "yes" or "no" and then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as confirmations. If the input is not recognized, it will ask again. The function does not return until it gets a valid response from the user.
func CreateDefaultConfigFile ¶
createDafaultConfigFile creates the default config.json template with sane defaults TODO: Will overwrite existing config.json, so ask for confirmation
func DBErrorCodeToHTTPErrorCode ¶
DBErrorCodeToHTTPErrorCode is a helper to translate error codes from the database into meaningful HTTP codes
func HyphensToUnderscores ¶
HyphensToUnderscores replaces all hyphens in the string with underscores. This is so you can use pretty URLs with hyphens (as recommended by Google) whilst still using underscores in App.DB table names - which means they don't have to be quoted all the time https://support.google.com/webmasters/answer/76329?hl=en
func MapToValsAndCols ¶
MapToValsAndCols iterates over the map resulting from binding a JSON request body and creates cols and vals strings to be used in SQL query
func RandomString ¶
RandomString generates a random string of int length
Types ¶
type Query ¶
type Query struct { //userQueryString is for when you need to provide complete, preformed SQL //This option will override any BaseAQL + args OverrideQueryString string //BaseSQL is a formatted SQL string with placeholder for SQLArgs BaseSQL string //SQLArgs are inserted into the BaseSQL in the order they appear SQLArgs []interface{} //SELECT fields Select []string //From Schema.Table Schema, Table string //Where Where []WhereConfig //Indicate whether to rquest JSON array or object //and when unmarshalling, whether map or slice of maps IsList bool //Role to execute the query as Role string //UserID to set on the query context UserID string //CacheLevel specifies the level of caching to use: all, role, user //Omitting, or using any other value, will bypass caching CacheLevel string //CacheExpiry CacheExpiry int // contains filtered or unexported fields }
Query is the basic building block of an SQL query
type ResponseError ¶
type ResponseError struct { HTTPCode int `json:"httpCode"` DBErrorCode pq.ErrorCode `json:"dbCode"` ErrorMessage string `json:"message"` Schema string `json:"schema"` Table string `json:"table"` Record string `json:"record"` }
ResponseError is the struct containing details of a server error
type WhereConfig ¶
type WhereConfig struct { Key string Operator string Value interface{} AnyValue []interface{} JoinWithOr bool }
WhereConfig describes one or more where clauses