mirror of
				https://github.com/aclindsa/moneygo.git
				synced 2025-11-04 10:33:25 -05:00 
			
		
		
		
	Lay groundwork and move sessions to 'store'
This commit is contained in:
		
							
								
								
									
										15
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								main.go
									
									
									
									
									
								
							@@ -3,11 +3,10 @@ package main
 | 
			
		||||
//go:generate make
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"database/sql"
 | 
			
		||||
	"flag"
 | 
			
		||||
	"github.com/aclindsa/moneygo/internal/config"
 | 
			
		||||
	"github.com/aclindsa/moneygo/internal/db"
 | 
			
		||||
	"github.com/aclindsa/moneygo/internal/handlers"
 | 
			
		||||
	"github.com/aclindsa/moneygo/internal/store/db"
 | 
			
		||||
	"github.com/kabukky/httpscerts"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net"
 | 
			
		||||
@@ -67,21 +66,15 @@ func staticHandler(w http.ResponseWriter, r *http.Request, basedir string) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	dsn := db.GetDSN(cfg.MoneyGo.DBType, cfg.MoneyGo.DSN)
 | 
			
		||||
	database, err := sql.Open(cfg.MoneyGo.DBType.String(), dsn)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	defer database.Close()
 | 
			
		||||
 | 
			
		||||
	dbmap, err := db.GetDbMap(database, cfg.MoneyGo.DBType)
 | 
			
		||||
	db, err := db.GetStore(cfg.MoneyGo.DBType, cfg.MoneyGo.DSN)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	defer db.Close()
 | 
			
		||||
 | 
			
		||||
	// Get ServeMux for API and add our own handlers for files
 | 
			
		||||
	servemux := http.NewServeMux()
 | 
			
		||||
	servemux.Handle("/v1/", &handlers.APIHandler{DB: dbmap})
 | 
			
		||||
	servemux.Handle("/v1/", &handlers.APIHandler{Store: db})
 | 
			
		||||
	servemux.HandleFunc("/", FileHandlerFunc(rootHandler, cfg.MoneyGo.Basedir))
 | 
			
		||||
	servemux.HandleFunc("/static/", FileHandlerFunc(staticHandler, cfg.MoneyGo.Basedir))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user