Documentation ¶
Overview ¶
Package seb contains generic functions
Index ¶
- Variables
- func AlreadyLoggedIn(req *http.Request) bool
- func AppendCSV(file string, newLines [][]string) error
- func CalcAverage(xi ...int) int
- func GetIP(req *http.Request) string
- func LoadConfig(fname string, i interface{}) error
- func MaxIntSlice(xi ...int) int
- func ReadCSV(file string) [][]string
- func ReadGob(i interface{}, fname string) error
- func ReverseXs(a []string) []string
- func ReverseXss(a [][]string) [][]string
- func SaveToGob(i interface{}, fname string) error
- func SaveToJSON(i interface{}, fileName string) error
- func SendMail(to []string, from, subj, body, password, domain, port string) error
- func StoTime(t string, days int) (time.Time, error)
- func StrToIntZ(s string) (int, error)
- func XlsxColNames(s interface{}) map[int]string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DbSessions = map[string]string{} // session ID, user ID
var DbUsers = map[string]user{} // user ID, user
Functions ¶
func AlreadyLoggedIn ¶
AlreadyLoggedIn checks if the UUID in the "session" cookie exists in the variable DbSessions and if that username still exist in our DbUsers
func AppendCSV ¶
AppendCSV takes a CSV filename and slice of new lines and adds the later to the existing CSV file.
func CalcAverage ¶
CalcAverage takes a variadic parameter of integers and returns the average integer.
func GetIP ¶
GetIP gets a requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.
func LoadConfig ¶
loadConfig loads configuration from a given json file (including folder) and loads it into i interface.
func MaxIntSlice ¶
MaxIntSlice takes a variadic parameter of integers and returns the highest integer.
Example ¶
fmt.Println(MaxIntSlice(0, 1, 2, 3, 4, 5, 6))
Output: 6
func ReadCSV ¶
ReadCSV reads a CSV file and returns the output as a slice of slice of string, where the main slice represents the rows and the subsequent slice the column values.
func ReverseXs ¶
ReverseXs takes a slice of string and returns the exact same slice in the the opposite order. If a is 10 long, then a[0] will be a[9] etc.
func ReverseXss ¶
ReverseXxs does exactly the same as ReverseXs but now for a slice of slice of string, where the first (main) slice is reversed. This can be used for example on the output of ReadCSV.
func SaveToJSON ¶
SaveToJson takes an interface, stores it into the filename and returns an error (or nil).
func SendMail ¶
SendMail sends an e-mail to one or more recipients. Example: SendMail([]string("recipient1@test.com", "recipient2@test.com"), "sender@test.com", "Subject", "Body", "12345", "smtp.gmail.com", "587"))
func StoTime ¶
StoTime receives a string of time (format hh:mm) and a day offset, and returns a type time with today's and the supplied hours and minutes + the offset in days.
func XlsxColNames ¶ added in v1.0.1
XlsxColNames takes a struct and returns a map of the xlsx tags in that struct (i.e. the columns) and the name of the associated struct field.
type User struct { Id int `validate:"-"` Name string `xlsx:"2"` Email string `validate:"3"` }
func main() { user := User{ Id: 1, Name: "John Doe", Email: "john@example", } colNames:= XlsxColNames(user) fmt.Println(colNames) fmt.Println(colNames["2"]) fmt.Println(colNames["3"]) }
Types ¶
This section is empty.