|
|
|
@ -12,14 +12,18 @@ import (
|
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
|
"gopkg.in/mgo.v2"
|
|
|
|
|
|
|
|
|
|
mongodbstore "github.com/2-72/gorilla-sessions-mongodb"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type App struct {
|
|
|
|
|
MongoClient *mongo.Client
|
|
|
|
|
MgoClient *mgo.Session
|
|
|
|
|
SpotifyAuth *spotifyauth.Authenticator
|
|
|
|
|
SpotifyOAuthConfig *oauth2.Config
|
|
|
|
|
Mux *chi.Mux
|
|
|
|
|
SessionStore *sessions.CookieStore
|
|
|
|
|
SessionStore sessions.Store
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a App) Run() {
|
|
|
|
@ -35,8 +39,6 @@ func (a App) Shutdown() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewApp() *App {
|
|
|
|
|
store := sessions.NewCookieStore([]byte(viper.GetString("server.sessionkey")))
|
|
|
|
|
|
|
|
|
|
serverAPI := options.ServerAPI(options.ServerAPIVersion1)
|
|
|
|
|
opts := options.Client().ApplyURI(viper.GetString("mongodb.uri")).SetServerAPIOptions(serverAPI)
|
|
|
|
|
// Create a new client and connect to the server
|
|
|
|
@ -45,6 +47,11 @@ func NewApp() *App {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
store, err := mongodbstore.NewMongoDBStore(client.Database("listy").Collection("sessions"), []byte(viper.GetString("server.sessionkey")))
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redirectURL := url.URL{
|
|
|
|
|
Scheme: viper.GetString("server.scheme"),
|
|
|
|
|
Host: viper.GetString("server.host"),
|
|
|
|
|