Add: backend session support and bug fix

This commit is contained in:
2021-12-12 01:13:26 +08:00
parent f3a95973e9
commit e608a6b1df
6 changed files with 123 additions and 26 deletions

View File

@@ -1,9 +1,11 @@
package api
import (
"github.com/gorilla/sessions"
"msw-open-music/pkg/database"
"msw-open-music/pkg/tmpfs"
"net/http"
"os"
)
type API struct {
@@ -12,6 +14,8 @@ type API struct {
token string
APIConfig APIConfig
Tmpfs *tmpfs.Tmpfs
store *sessions.CookieStore
defaultSessionName string
}
func NewAPIConfig() APIConfig {
@@ -43,6 +47,8 @@ func NewAPI(config Config) (*API, error) {
return nil, err
}
store := sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY")))
mux := http.NewServeMux()
apiMux := http.NewServeMux()
@@ -53,6 +59,8 @@ func NewAPI(config Config) (*API, error) {
Handler: mux,
},
APIConfig: apiConfig,
store: store,
defaultSessionName: "msw-open-music",
}
api.Tmpfs = tmpfs.NewTmpfs(tmpfsConfig)