You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
package main |
|
|
|
import ( |
|
"github.com/gin-gonic/gin" |
|
"github.com/gorilla/sessions" |
|
"github.com/joho/godotenv" |
|
"github.com/markbates/goth" |
|
"github.com/markbates/goth/gothic" |
|
"github.com/markbates/goth/providers/twitch" |
|
"log" |
|
"os" |
|
"sponsorahacker/auth" |
|
"sponsorahacker/config" |
|
"sponsorahacker/pages" |
|
) |
|
|
|
// route to authenticate |
|
// route for log |
|
func main() { |
|
r := gin.Default() |
|
r.LoadHTMLGlob("templates/*") |
|
r.Static("/assets", "./assets") |
|
|
|
err := godotenv.Load() |
|
if err != nil { |
|
log.Fatal("Error loading .env file") |
|
} |
|
|
|
sessionSecret := config.GetEnvVar("SESSION_SECRET") |
|
gothic.Store = sessions.NewCookieStore([]byte(sessionSecret)) |
|
goth.UseProviders( |
|
twitch.New(os.Getenv("TWITCH_CLIENT_ID"), os.Getenv("TWITCH_SECRET"), "http://localhost:8080/auth/twitch/callback"), |
|
// google.New(os.Getenv("GOOGLE_CLIENT_ID"), os.Getenv("GOOGLE_SECRET"), "http://localhost:8080/auth/google/callback"), |
|
// twitter.New(os.Getenv("TWITTER_CLIENT_ID"), os.Getenv("TWITTER_SECRET"), "http://localhost:8080/auth/twitter/callback"), |
|
) |
|
|
|
// auth routes |
|
r.GET("/auth/login/:provider", auth.Login) |
|
r.GET("/auth/:provider/callback", auth.Callback) |
|
r.GET("/auth/logout/:provider", auth.Logout) |
|
|
|
// pages routes |
|
r.GET("/", pages.Home) |
|
r.GET("/login", pages.Login) |
|
r.GET("/welcome", pages.Welcome) |
|
r.GET("/goals", pages.Goals) |
|
r.GET("/goals/:goalId", pages.Goal) |
|
// post routes |
|
r.POST("/goals", pages.CreateGoal) |
|
err = r.Run(":8080") |
|
|
|
if err != nil { |
|
panic(err) |
|
} |
|
}
|
|
|