Documentation ¶
Overview ¶
Package ginServer contains the gin server and ginServer helper functions
Index ¶
- Constants
- Variables
- func AddRouterGroup(group string, route string, method string, fp func(*gin.Context))
- func CheckLastModified(w http.ResponseWriter, r *http.Request, modtime time.Time) bool
- func ClearSession(c *gin.Context)
- func ConfigureGin(mode string, cookieDomain string, secureHeaders bool, allowedHosts []string, ...)
- func GetRequestBody(c *gin.Context) ([]byte, error)
- func GetSessionKey(c *gin.Context, key string) (sessionKey string)
- func Initialize(mode string, cookieDomain string)
- func InitializeLite(mode string, secureHeaders bool, allowedHosts []string)
- func ReadFileBase64(path string, c *gin.Context)
- func ReadGzipCSSFile(path string, c *gin.Context)
- func ReadGzipJSFile(path string, c *gin.Context)
- func ReadHTMLFile(path string, c *gin.Context)
- func ReadJSFile(path string, c *gin.Context)
- func ReadJSONFile(path string, c *gin.Context)
- func ReadJpgFile(path string, c *gin.Context)
- func ReadPngFile(path string, c *gin.Context)
- func RenderHTML(html string, c *gin.Context)
- func RespondCSSFile(data []byte, modTime time.Time, c *gin.Context)
- func RespondEotFile(data []byte, modTime time.Time, c *gin.Context)
- func RespondError(message string) []byte
- func RespondGzipCSSFile(data []byte, modTime time.Time, c *gin.Context)
- func RespondGzipJSFile(data []byte, modTime time.Time, c *gin.Context)
- func RespondJSFile(data []byte, modTime time.Time, c *gin.Context)
- func RespondJSON(v interface{}, c *gin.Context)
- func RespondOtfFile(data []byte, modTime time.Time, c *gin.Context)
- func RespondSvgFile(data []byte, modTime time.Time, c *gin.Context)
- func RespondTtfFile(data []byte, modTime time.Time, c *gin.Context)
- func RespondWoff2File(data []byte, modTime time.Time, c *gin.Context)
- func RespondWoffFile(data []byte, modTime time.Time, c *gin.Context)
- func SaveSession(c *gin.Context)
- func SetSessionKey(c *gin.Context, key string, value string)
- type ErrorResponse
- type LocaleLanguage
- type SessionConfiguration
Examples ¶
Constants ¶
const StatusNotModified = 304 // RFC 7232, 4.1
StatusNotModified returns a 304 HTTP status code.
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
TImeFormat useful for formatting timestamps
Variables ¶
var Router *gin.Engine
Router is the main gin.Engine that is used to serve all requests
Functions ¶
func AddRouterGroup ¶
AddRouterGroup adds a gin-gonic router group to the gin server
func CheckLastModified ¶
CheckLastModified modtime is the modification time of the resource to be served, or IsZero(). return value is whether this request is now complete.
func ClearSession ¶
ClearSession clears the session of the client.
func ConfigureGin ¶
func ConfigureGin(mode string, cookieDomain string, secureHeaders bool, allowedHosts []string, cookieSession SessionConfiguration, launchPprof bool)
ConfigureGin sets up all the GoCore features we currently offer
Example ¶
Simple example using csrf security, session cookies, and a custom port.
package main import ( "github.com/DanielRenne/GoCore/core/ginServer" ) func main() { cookieConfig := ginServer.SessionConfiguration{ Enabled: true, SessionKey: "test", SessionName: "test", SessionExpirationDays: 15, SessionSecureCookie: false, } ginServer.ConfigureGin("debug", "", false, []string{}, cookieConfig, true) // Run this if you want to use the gin server after configuring it how you want // import "github.com/DanielRenne/GoCore/core/app" // app.RunLite(9090) }
Output:
func GetRequestBody ¶
GetRequestBody returns the body of the request as a string.
func GetSessionKey ¶
GetSessionKey returns a thread-safe value of the session key.
func Initialize ¶
Initialize is an internal export used in app/app.go based on your webConfig.json
func InitializeLite ¶
InitializeLite is an internal export used in app/app.go based on if you use app.InitializeLite()
func ReadFileBase64 ¶
ReadFileBase64 reads a file and responds with a base64 encoded string. Primarily used for jquery ajax response binary data blob encoding.
func ReadGzipCSSFile ¶
ReadGzipCSSFile reads a file from the path parameter and returns to the client as text/css.
func ReadGzipJSFile ¶
ReadGzipJSFile reads a file from the path parameter and returns to the client as application/gzip.
func ReadHTMLFile ¶
ReadHTMLFile reads a file from the path parameter and returns to the client as text/html.
func ReadJSFile ¶
ReadJSFile reads a file from the path parameter and returns to the client as text/javascript.
func ReadJSONFile ¶
ReadJSONFile reads a file from the path parameter and returns to the client application/json
func ReadJpgFile ¶
ReadJpgFile reads a file from the path parameter and returns to the client as image/jpeg.
func ReadPngFile ¶
ReadPngFile reads a file from the path parameter and returns to the client as image/png.
func RenderHTML ¶
RenderHTML takes a string and returns to the client as text/html.
func RespondCSSFile ¶
RespondCSSFile returns a file to the client as text/css.
func RespondEotFile ¶
RespondEotFile returns a file to the client as application/vnd.ms-fontobject.
func RespondError ¶
RespondError returns an byte array comprised of a JSON formated object with the error message.
func RespondGzipCSSFile ¶
RespondGzipCSSFile returns a file to the client as text/css.
func RespondGzipJSFile ¶
RespondGzipJSFile returns a file to the client as application/gzip.
func RespondJSFile ¶
RespondJSFile returns a file to the client as application/javascript.
func RespondJSON ¶
RespondJSON returns to the client application/json format for the passed interface.
func RespondOtfFile ¶
RespondOtfFile returns a file to the client as application/x-font-opentype.
func RespondSvgFile ¶
ResondSvgFile returns a file to the client as image/svg+xml.
func RespondTtfFile ¶
ResponsdTtfFile returns a file to the client as application/x-font-ttf.
func RespondWoff2File ¶
ResondWoff2File returns a file to the client as application/font-woff2.
func RespondWoffFile ¶
ResondWoffFile returns a file to the client as application/font-woff.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Message string `json:"message"`
}
ErrorResonse is a struct that is used to return errors to the client.
type LocaleLanguage ¶
LocaleLanguage is a struct that is used to return the language and locale of the client.
func GetLocaleLanguage ¶
func GetLocaleLanguage(c *gin.Context) (ll LocaleLanguage)
GetLocaleLanguage returns the locale and language of the client.