seb

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: MIT Imports: 13 Imported by: 2

Documentation

Overview

Package seb contains generic functions

Index

Examples

Constants

This section is empty.

Variables

View Source
var DbSessions = map[string]string{} // session ID, user ID
View Source
var DbUsers = map[string]user{} // user ID, user

Functions

func AlreadyLoggedIn

func AlreadyLoggedIn(req *http.Request) bool

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

func AppendCSV(file string, newLines [][]string) error

AppendCSV takes a CSV filename and slice of new lines and adds the later to the existing CSV file.

func CalcAverage

func CalcAverage(xi ...int) int

CalcAverage takes a variadic parameter of integers and returns the average integer.

func GetIP

func GetIP(req *http.Request) string

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

func LoadConfig(fname string, i interface{}) error

loadConfig loads configuration from a given json file (including folder) and loads it into i interface.

func MaxIntSlice

func MaxIntSlice(xi ...int) int

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

func ReadCSV(file string) [][]string

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 ReadGob

func ReadGob(i interface{}, fname string) error

ReadGob reads a gob from a file and converts it into an interface.

func ReverseXs

func ReverseXs(a []string) []string

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

func ReverseXss(a [][]string) [][]string

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 SaveToGob

func SaveToGob(i interface{}, fname string) error

SaveGob encodes an interface and stores it as a Gob into a file named fname.

func SaveToJSON

func SaveToJSON(i interface{}, fileName string) error

SaveToJson takes an interface, stores it into the filename and returns an error (or nil).

func SendMail

func SendMail(to []string, from, subj, body, password, domain, port string) error

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

func StoTime(t string, days int) (time.Time, error)

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 StrToIntZ

func StrToIntZ(s string) (int, error)

StrToInt transforms string to an int and returns a positive int or zero.

func XlsxColNames added in v1.0.1

func XlsxColNames(s interface{}) map[int]string

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.

Directories

Path Synopsis
examples
gob

Jump to

Keyboard shortcuts

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