Skip to content

Instantly share code, notes, and snippets.

View hashbender's full-sized avatar
👷‍♂️
Buidling

Nick Hansen hashbender

👷‍♂️
Buidling
View GitHub Profile
package main
import (
"database/sql"
)
var (
db *sql.DB
)
func main() {
//ContextedHandler is a wrapper to provide AppContext to our Handlers
type ContextedHandler struct {
*AppContext
//ContextedHandlerFunc is the interface which our Handlers will implement
ContextedHandlerFunc func(*AppContext, http.ResponseWriter, *http.Request) (int, error)
}
//AppContext provides the app context to handlers. This *cannot* contain request-specific keys like
//sessionId or similar. It is shared across requests.
type AppContext struct {
@hashbender
hashbender / contexted_impl.go
Last active April 20, 2017 20:35
Implements ContextedHandlerFunc
//HelloWorldHandler just prints a Hello World on a GET request
func HelloWorldHandler(c *AppContext, w http.ResponseWriter, req *http.Request) (int, error) {
//So in this handler we now have the context provided
fmt.Fprint(w, "Hello World")
return http.StatusOK, nil
}
func main() {
context := AppContext{Db: initDb(), Redis: initRedis()}
@hashbender
hashbender / route.go
Last active April 20, 2017 21:48
route declarations
//Route this struct is used for declaring a route
type Route struct {
Name string
Method []string
Pattern string
ContextedHandler *ContextedHandler
}
//Routes just stores our Route declarations
type Routes []Route
@hashbender
hashbender / middlewares.go
Created April 20, 2017 22:04
middlewares
//CheckAuth is an example middleware which demonstrates how we *might* check auth.
func CheckAuth(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
//TODO this is just an example.
//Get the cookie or something and check it
cookie, err := r.Cookie("session")
if err != nil || cookie == nil {
// TODO if an err, then redirect
// http.Redirect(w, r, "/", 401)
}
@hashbender
hashbender / newrouter.go
Created April 20, 2017 22:25
newrouter
//NewRouter returns a new Gorrila Mux router
func NewRouter(c AppContext) *mux.Router {
router := mux.NewRouter().StrictSlash(true)
appContext = c
for _, route := range routes {
//Check all routes to make sure the users are properly authenticated
router.
Methods(route.Method...).
Path(route.Pattern).
@hashbender
hashbender / NewRouter.go
Created April 20, 2017 22:28
Complete NewRouter
//NewRouter returns a new Gorrila Mux router
func NewRouter(c AppContext) *mux.Router {
router := mux.NewRouter().StrictSlash(true)
appContext = c
for _, route := range routes {
//Check all routes to make sure the users are properly authenticated
router.
Methods(route.Method...).
Path(route.Pattern).
nick.hansen@nickhansen-ltm6~/PersonalCode/Go/src/github.com/rippaio/sia-stratum: docker logs e395f72a6191
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.

Keybase proof

I hereby claim:

  • I am nitronick600 on github.
  • I am nickhansen (https://keybase.io/nickhansen) on keybase.
  • I have a public key whose fingerprint is DEA5 D49C F915 9DB5 82EC 7721 2247 1344 2D8F 8FC3

To claim this, I am signing this object:

Whoops, looks like something went wrong.
2/2
QueryException in Connection.php line 729:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'address' cannot be null (SQL: insert into `address_details` (`user_id`, `address`, `public_key`, `private_key`) values (58, , , eyJpdiI6IjdIdmkwVlZoUmpzd25PNlwvS0h3dHhBPT0iLCJ2YWx1ZSI6Ik5uTGlxbXl4Vk1VQnF1eHA4OFZKRlE9PSIsIm1hYyI6IjZjNzhiZmZkZTU1ZTQxYmM4ODg2OTRhN2Q1NzlmNWYxYWVmYTkyNzY5M2NhYzQ2OTkyZjFlMDE4YWFjZDNiNTYifQ==))
in Connection.php line 729
at Connection->runQueryCallback('insert into `address_details` (`user_id`, `address`, `public_key`, `private_key`) values (?, ?, ?, ?)', array('58', null, null, 'eyJpdiI6IjdIdmkwVlZoUmpzd25PNlwvS0h3dHhBPT0iLCJ2YWx1ZSI6Ik5uTGlxbXl4Vk1VQnF1eHA4OFZKRlE9PSIsIm1hYyI6IjZjNzhiZmZkZTU1ZTQxYmM4ODg2OTRhN2Q1NzlmNWYxYWVmYTkyNzY5M2NhYzQ2OTkyZjFlMDE4YWFjZDNiNTYifQ=='), object(Closure)) in Connection.php line 685
at Connection->run('insert into `address_details` (`user_id`, `address`, `public_key`, `private_key`) values (?, ?, ?, ?)