* if a request has no session cookie, a new user, session and wallet is created and session cookie is set * if a request has a session cookie and session exists in db, we will fetch user and wallet from db * this means that we have a user and wallet during each render without any login required
		
			
				
	
	
		
			25 lines
		
	
	
		
			302 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			302 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package db
 | |
| 
 | |
| import (
 | |
| 	"database/sql"
 | |
| 
 | |
| 	_ "github.com/lib/pq"
 | |
| )
 | |
| 
 | |
| type DB struct {
 | |
| 	*sql.DB
 | |
| }
 | |
| 
 | |
| func New(dbUrl string) (*DB, error) {
 | |
| 	// open connection
 | |
| 	db_, err := sql.Open("postgres", dbUrl)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	// TODO: run migrations
 | |
| 	db := &DB{DB: db_}
 | |
| 
 | |
| 	return db, db_.Ping()
 | |
| }
 |