inceptus

module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: MIT

Directories

Path Synopsis
Package conf provide functions for loading config from yaml file or env variables
Package conf provide functions for loading config from yaml file or env variables
Package db provides Pool for communicationg with Postgre database Example usage: // Preparing database connection pool DBPool, err := db.New( fmt.Sprintf("host=%s port=%s user=%s password=%s database=%s", config.Database.Host, config.Database.Port, config.Database.User, config.Database.Password, config.Database.Database), logger, config.Database.Connections.MaxIdle, config.Database.Connections.MaxLife, config.Database.Connections.MaxOpenIdle, config.Database.Connections.MaxOpen, ) // Creating table _, err := DBPool.ExecContext(context.Background(), "CREATE TABLE IF NOT EXISTS dummy(name TEXT);") if err != nil { fmt.Fprintf(os.Stderr, "table creation failed: %v\n", err) os.Exit(1) } // Adding data to table _, err := DBPool.ExecContext(context.Background(), "insert into dummy(name) values($1)", "app item") if err != nil { fmt.Fprintf(os.Stderr, "Insert failed: %v\n", err) os.Exit(1) } // Selecting data from table rows, _ := DBPool.QueryContext(context.Background(), "select * from dummy") for rows.Next() { var name string err := rows.Scan(&name) if err != nil { fmt.Fprintf(os.Stderr, "Scan failed: %v\n", err) } fmt.Printf("%s\n", name) }
Package db provides Pool for communicationg with Postgre database Example usage: // Preparing database connection pool DBPool, err := db.New( fmt.Sprintf("host=%s port=%s user=%s password=%s database=%s", config.Database.Host, config.Database.Port, config.Database.User, config.Database.Password, config.Database.Database), logger, config.Database.Connections.MaxIdle, config.Database.Connections.MaxLife, config.Database.Connections.MaxOpenIdle, config.Database.Connections.MaxOpen, ) // Creating table _, err := DBPool.ExecContext(context.Background(), "CREATE TABLE IF NOT EXISTS dummy(name TEXT);") if err != nil { fmt.Fprintf(os.Stderr, "table creation failed: %v\n", err) os.Exit(1) } // Adding data to table _, err := DBPool.ExecContext(context.Background(), "insert into dummy(name) values($1)", "app item") if err != nil { fmt.Fprintf(os.Stderr, "Insert failed: %v\n", err) os.Exit(1) } // Selecting data from table rows, _ := DBPool.QueryContext(context.Background(), "select * from dummy") for rows.Next() { var name string err := rows.Scan(&name) if err != nil { fmt.Fprintf(os.Stderr, "Scan failed: %v\n", err) } fmt.Printf("%s\n", name) }
Package helpers contains some useful functions, currently: generating uuid, md5 from string, sourceIp
Package helpers contains some useful functions, currently: generating uuid, md5 from string, sourceIp
Package life provides application wide context with cancel function and some helper functions to register syscalls for smooth app termination and reloading (conf, logger and such)
Package life provides application wide context with cancel function and some helper functions to register syscalls for smooth app termination and reloading (conf, logger and such)
Package route and its subpackages provides most of what you need for http server
Package route and its subpackages provides most of what you need for http server
ctx
Package ctx contains setters and getters for request context
Package ctx contains setters and getters for request context
middleware
Package middleware contains middlewares for logging, auth, custom errors and so on
Package middleware contains middlewares for logging, auth, custom errors and so on
Package serialize provides unified interface for encoding and decoding data with several implementations (JSON, MsgPack, Gob, ..) Example usage: var err error var byteCoder serialize.ByteCoder byteCoder = &serialize.JSONCoder{} byteCoder = &serialize.MsgPackCoder{} type MyStruct struct { A int B string } dataToSerialize := MyStruct{A: 100, B: "hey"} encodedBytes, err := byteCoder.Encode(dataToSerialize) if err != nil { fmt.Fprintf(os.Stderr, "serialization failed: %v\n", err) os.Exit(1) } decodedData := MyStruct{} err = byteCoder.Decode(encodedBytes, &decodedData) if err != nil { fmt.Fprintf(os.Stderr, "deserialization failed: %v\n", err) os.Exit(1) } fmt.Printf( "Original: %v\nSerialized: %v\nDecoded: %v\n", dataToSerialize, encodedBytes, decodedData) Will print out: Original: {100 hey} Serialized: [130 161 65 100 161 66 163 104 101 121] Decoded: {100 hey}
Package serialize provides unified interface for encoding and decoding data with several implementations (JSON, MsgPack, Gob, ..) Example usage: var err error var byteCoder serialize.ByteCoder byteCoder = &serialize.JSONCoder{} byteCoder = &serialize.MsgPackCoder{} type MyStruct struct { A int B string } dataToSerialize := MyStruct{A: 100, B: "hey"} encodedBytes, err := byteCoder.Encode(dataToSerialize) if err != nil { fmt.Fprintf(os.Stderr, "serialization failed: %v\n", err) os.Exit(1) } decodedData := MyStruct{} err = byteCoder.Decode(encodedBytes, &decodedData) if err != nil { fmt.Fprintf(os.Stderr, "deserialization failed: %v\n", err) os.Exit(1) } fmt.Printf( "Original: %v\nSerialized: %v\nDecoded: %v\n", dataToSerialize, encodedBytes, decodedData) Will print out: Original: {100 hey} Serialized: [130 161 65 100 161 66 163 104 101 121] Decoded: {100 hey}

Jump to

Keyboard shortcuts

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