Documentation
¶
Index ¶
- func CalculateStringDistance(baseDistance int, name string) string
- func FindStringInSlice(str string, sl []string) bool
- func GetCurrentDateTime() string
- func HandleError(err error)
- func IsEmpty(field string) bool
- func LogMessage(message string)
- func SetResponse(w http.ResponseWriter, statusCode int, body HTTPResponse)
- type HTTPResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateStringDistance ¶
CalculateStringDistance calculates the number of empty characters required to match a longer string above it (i.e. in a printed table)
Receives:
- baseDistance (int) - Length of the string to match
- name (string) - String to add empty characters to
Returns:
- string - New string with the required added spaces to match the string above it
func FindStringInSlice ¶
FindStringInSlice detects if a string is in a slice.
Receives:
- str (string) - String that will be searched inside the slice
- sl ([]string) - Slice of strings
Returns:
- bool - Whether or not the string was found inside the slice
func GetCurrentDateTime ¶
func GetCurrentDateTime() string
GetCurrentDateTime returns the current date/time
- Returns: string - Current date/time in YYYY-mm-dd HH:ii::ss format
func HandleError ¶
func HandleError(err error)
HandleError is a basic error handling method. Prints out the error that occurred and exits the application.
func LogMessage ¶
func LogMessage(message string)
LogMessage simply logs a message to the console with the current date/time.
func SetResponse ¶
func SetResponse(w http.ResponseWriter, statusCode int, body HTTPResponse)
SetResponse sets the response to be sent to the user in any API endpoints.
Receives:
- w (http.ResponseWriter) - Go's HTTP ResponseWriter struct
- statusCode (int) - HTTP status code of the response
- body (HTTPResponse) - Body of the HTTP response using a custom struct
Types ¶
type HTTPResponse ¶
type HTTPResponse struct { Success bool `json:"success"` // Whether the request was successful or not Rows int `json:"rows"` // Number of rows in the Data interface response Data interface{} `json:"data"` // Interface that has the relevant information to return. Can be a slice, object, string, etc. Error string `json:"error"` // Error message (in case an error occurred) }
HTTPResponse is the struct used to send back JSON responses in the API
Click to show internal directories.
Click to hide internal directories.