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