Documentation ¶
Overview ¶
This module contains helper functions primary focused on Google Cloud Platform
Index ¶
- Constants
- func AddServiceAccountUserRole(impersonateAccount string, targetAccount string, principalAccount string) error
- func BadRequest(c *gin.Context, message string)
- func CatMode(r *http.Request)
- func CheckBody(w http.ResponseWriter, r *http.Request)
- func ConnectCloudSQL(database string) *sql.DB
- func ConvertToBoolPointer(value interface{}) *bool
- func GetFavicon(w http.ResponseWriter, r *http.Request)
- func GetProjectFromServiceAccount(serviceAccount string) string
- func GormDatabase(databaseName string) *gorm.DB
- func HealthCheck(w http.ResponseWriter, r *http.Request)
- func ImpersonateSA(context context.Context, serviceAccount string, scope string) (token oauth2.TokenSource, err error)
- func List2String(values []string) string
- func Logger(message string, level string)
- func MessageHelper(w http.ResponseWriter, message string)
- func MustGetenv(k string) string
- func RemoveServiceAccountUserRole(impersonateAccount string, targetAccount string, principalAccount string) error
- func ResponseMessage(ctx *gin.Context, code int, message ...string)
- func UndefinedAnswer(w http.ResponseWriter, r *http.Request)
- func WrongParameter(w http.ResponseWriter, r *http.Request)
- func WrongPath() http.Handler
- type Message
- type TimestampSerializer
Constants ¶
const WrongMessage = "What are you doing here?"
Variables ¶
This section is empty.
Functions ¶
func AddServiceAccountUserRole ¶ added in v1.2.0
func BadRequest ¶ added in v1.5.0
BadRequest is a simple function that returns a bad request message in JSON format with a BadRequest status code for Gin
func CatMode ¶ added in v1.3.3
CatMode is a function that will print the request information It will print the URL, Method, Headers and Body of the request It is used to debug the request information
func CheckBody ¶ added in v1.3.0
func CheckBody(w http.ResponseWriter, r *http.Request)
CheckBody is a function that will print the request information It will print the URL, Method, Headers and Body of the request It is used to debug the request information Needs to be used with io.TeeReader to be able to read the body multiple times Example:
- http.HandleFunc("/", CheckBody)
Output:
- Request information:
- Request URL: /?test=1
- Request Method: GET
- Request Headers: map[Accept:[*/*] Accept-Encoding:[gzip] User-Agent:Go-http-client/1.1]
- Request Body: test=1
func ConnectCloudSQL ¶ added in v1.0.0
func ConvertToBoolPointer ¶ added in v1.4.0
func ConvertToBoolPointer(value interface{}) *bool
ConvertToBoolPointer is a simple function that converts a interface to a *bool
func GetFavicon ¶ added in v1.1.0
func GetFavicon(w http.ResponseWriter, r *http.Request)
func GetProjectFromServiceAccount ¶ added in v1.2.1
func GormDatabase ¶ added in v1.4.0
GormDatabase is a function that returns a GORM database connection - Use simple Structure to connect to the database - Use the following environment variables:
- DATABASE_USER
- DATABASE_PASS
- DATABASE_IP
Works only with MySQL databases (for now)
func HealthCheck ¶
func HealthCheck(w http.ResponseWriter, r *http.Request)
func ImpersonateSA ¶ added in v1.0.0
func List2String ¶ added in v1.5.0
List2String converts a list of strings to a string in the format ["value1","value2"]
func MessageHelper ¶ added in v1.0.0
func MessageHelper(w http.ResponseWriter, message string)
func MustGetenv ¶
MustGetenv validates if the environment variable is set and returns it otherwise it will log a fatal error and exit the program It is used to validate the environment variables Example:
- os.Setenv("TEST", "test")
- log.Println(MustGetenv("TEST"))
- log.Println(MustGetenv("TEST2"))
Output:
- test
- 2021/08/31 11:30:00 Missing environment variable: TEST2
- exit status 1
func RemoveServiceAccountUserRole ¶ added in v1.2.0
func ResponseMessage ¶ added in v1.5.0
ResponseMessage is a simple function that returns a message in JSON format with a status code for Gin
func UndefinedAnswer ¶
func UndefinedAnswer(w http.ResponseWriter, r *http.Request)
func WrongParameter ¶ added in v1.0.0
func WrongParameter(w http.ResponseWriter, r *http.Request)
Types ¶
type TimestampSerializer ¶ added in v1.4.0
type TimestampSerializer struct { }
TimestampSerializer is a custom serializer for GORM to handle timestamps values