HEAVY: migrate accounts and logs to service/repo architecture
This commit is contained in:
parent
5c255fb34b
commit
49e14b5bc5
37 changed files with 1019 additions and 687 deletions
21
api/api.go
21
api/api.go
|
|
@ -1,17 +1,18 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/model/app"
|
||||
)
|
||||
|
||||
func Handler(app *model.AppState) http.Handler {
|
||||
func Handler(app *app.AppState) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// TODO: generate API keys on the frontend
|
||||
|
|
@ -166,7 +167,7 @@ func requireAccount(next http.Handler) http.Handler {
|
|||
})
|
||||
}
|
||||
|
||||
func getSession(app *model.AppState, r *http.Request) (*model.Session, error) {
|
||||
func getSession(app *app.AppState, r *http.Request) (*model.Session, error) {
|
||||
var token string
|
||||
|
||||
// check cookies first
|
||||
|
|
@ -184,7 +185,7 @@ func getSession(app *model.AppState, r *http.Request) (*model.Session, error) {
|
|||
if token == "" { return nil, nil }
|
||||
|
||||
// fetch existing session
|
||||
session, err := controller.GetSession(app.DB, token)
|
||||
session, err := controller.GetSession(app, token)
|
||||
|
||||
if err != nil && !strings.Contains(err.Error(), "no rows") {
|
||||
return nil, fmt.Errorf("Failed to retrieve session: %v\n", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue