common

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: GPL-3.0 Imports: 35 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Common

type Common struct {
	AppName  string
	Debug    bool
	Version  string
	RootPath string
	Routes   *chi.Mux
	DB       *gorm.DB
	S3       *session.Session

	EncryptionKey string
	Cache         cache.Cache
	Server        Server
	// contains filtered or unexported fields
}

func (*Common) BuildDSN

func (c *Common) BuildDSN() string

BuildDSN builds the datasource name for our database, and returns it as a string

func (*Common) CreateDirIfNotExist

func (c *Common) CreateDirIfNotExist(path string) error

CreateDirIfNotExist creates a new directory if it does not exist

func (*Common) CreateFileIfNotExists

func (c *Common) CreateFileIfNotExists(path string) error

CreateFileIfNotExists creates a new file at path if it does not exist

func (*Common) DownloadFile

func (c *Common) DownloadFile(w http.ResponseWriter, r *http.Request, pathToFile, fileName string) error

DownloadFile downloads a file

func (*Common) Error404

func (c *Common) Error404(w http.ResponseWriter, r *http.Request)

Error404 returns page not found response

func (*Common) Error500

func (c *Common) Error500(w http.ResponseWriter, r *http.Request)

Error500 returns internal server error response

func (*Common) ErrorForbidden

func (c *Common) ErrorForbidden(w http.ResponseWriter, r *http.Request)

ErrorForbidden returns a forbidden status message (client is known)

func (*Common) ErrorStatus

func (c *Common) ErrorStatus(w http.ResponseWriter, status int)

ErrorStatus returns a response with the supplied http status

func (*Common) ErrorUnauthorized

func (c *Common) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)

ErrorUnauthorized sends an unauthorized status (client is not known)

func (*Common) ListenAndServe

func (c *Common) ListenAndServe()

ListenAndServe starts the web server

func (*Common) LoadTime

func (c *Common) LoadTime(start time.Time)

func (*Common) New

func (c *Common) New(rootPath string) error

func (*Common) OpenDB

func (c *Common) OpenDB(dbType, dsn string) (*sql.DB, error)

func (*Common) RandomString

func (c *Common) RandomString(n int) string

RandomString generates a random string length n from values in the const randomString

func (*Common) ReadJSON

func (c *Common) ReadJSON(w http.ResponseWriter, r *http.Request, data interface{}) error

func (*Common) WriteJSON

func (c *Common) WriteJSON(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error

WriteJSON writes json from arbitrary data

type Database

type Database struct {
	DataType string
	Pool     *sql.DB
}

type DatabaseConfig

type DatabaseConfig struct {
	// contains filtered or unexported fields
}

func (*DatabaseConfig) BuildDSN

func (d *DatabaseConfig) BuildDSN() string

func (*DatabaseConfig) OpenDbConn

func (d *DatabaseConfig) OpenDbConn() (db.Session, error)

type Encryption

type Encryption struct {
	Key []byte
}

func (*Encryption) Decrypt

func (e *Encryption) Decrypt(cryptoText string) (string, error)

func (*Encryption) Encrypt

func (e *Encryption) Encrypt(text string) (string, error)

type JsonApiResponse

type JsonApiResponse struct {
	Success bool        `json:"success"`
	Status  int         `json:"status"`
	Data    interface{} `json:"data"`
}

type Server

type Server struct {
	ServerName string
	Port       string
	Secure     bool
	URL        string
}

Jump to

Keyboard shortcuts

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