Skip to content

Commit

Permalink
resolves todo about init
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh committed Sep 8, 2021
1 parent 3f244fe commit e431663
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 59 deletions.
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
4 changes: 2 additions & 2 deletions examples/with-gin/go.mod → examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/supertokens/supertokens-golang/examples/with-gin
module github.com/supertokens/supertokens-golang/examples

go 1.15

Expand All @@ -7,5 +7,5 @@ require (
github.com/gin-gonic/gin v1.7.4
github.com/google/logger v1.1.1
github.com/spf13/viper v1.8.1
github.com/supertokens/supertokens-golang v0.0.0-20210907184146-c3f4342c5169
github.com/supertokens/supertokens-golang v0.0.0-20210907185255-3f244feb49e1
)
6 changes: 2 additions & 4 deletions examples/with-gin/go.sum → examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/supertokens/supertokens-golang v0.0.0-20210703150908-deff5f43548e h1:rdQk26ke+1fADofup7LbWEmO3SYvutPAaJ40XfuLJYI=
github.com/supertokens/supertokens-golang v0.0.0-20210907184146-c3f4342c5169 h1:3xrtII8Qc0xOIVs9Icuqs45CPlS4Ppl21pvCRrmmmcA=
github.com/supertokens/supertokens-golang v0.0.0-20210907184146-c3f4342c5169/go.mod h1:kjG5NySXy8gv6DO0VENQNk5PAbgHLEiTj4WLjNuqn94=
github.com/supertokens/supertokens-golang v0.0.0-20210907185255-3f244feb49e1 h1:vYv2rbMBOz35oGADtvNc/bDriieI0b841bYYCAhEPBA=
github.com/supertokens/supertokens-golang v0.0.0-20210907185255-3f244feb49e1/go.mod h1:kjG5NySXy8gv6DO0VENQNk5PAbgHLEiTj4WLjNuqn94=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
Expand Down Expand Up @@ -443,7 +442,6 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
45 changes: 0 additions & 45 deletions examples/with-gin/server/router.go

This file was deleted.

39 changes: 37 additions & 2 deletions examples/with-gin/server/server.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
package server

import (
"fmt"
"log"
"time"

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/supertokens/supertokens-golang/examples/with-gin/config"
"github.com/supertokens/supertokens-golang/examples/with-gin/controllers"
"github.com/supertokens/supertokens-golang/examples/with-gin/middlewares"
"github.com/supertokens/supertokens-golang/supertokens"
)

func Init() {
config := config.GetConfig()

r := newRouter()
err := r.Run(config.GetString("server.apiPort"))
router := gin.New()
router.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
param.ClientIP,
param.TimeStamp.Format(time.RFC1123),
param.Method,
param.Path,
param.Request.Proto,
param.StatusCode,
param.Latency,
param.Request.UserAgent(),
param.ErrorMessage,
)
}))

router.Use(gin.Recovery())

router.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:3000"},
AllowMethods: []string{"GET", "POST", "DELETE", "PUT", "OPTIONS"},
AllowHeaders: append([]string{"content-type"}, supertokens.GetAllCORSHeaders()...),
MaxAge: 1 * time.Minute,
AllowCredentials: true,
}))

router.Use(middlewares.Supertokens())

router.GET("/sessioninfo", middlewares.VerifySession(nil), controllers.Sessioninfo)

err := router.Run(config.GetString("server.apiPort"))
if err != nil {
log.Println("error running server => ", err)
}
Expand Down
5 changes: 5 additions & 0 deletions examples/with-http/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {

}
3 changes: 1 addition & 2 deletions recipe/emailpassword/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/supertokens/supertokens-golang/supertokens"
)

// TODO: change this to and others to just Init
func EmailPasswordInit(config *models.TypeInput) supertokens.RecipeListFunction {
func Init(config *models.TypeInput) supertokens.RecipeListFunction {
return recipeInit(config)
}

Expand Down
2 changes: 1 addition & 1 deletion recipe/emailverification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/supertokens/supertokens-golang/supertokens"
)

func EmailVerificationInit(config *models.TypeInput) supertokens.RecipeListFunction {
func Init(config *models.TypeInput) supertokens.RecipeListFunction {
return recipeInit(config)
}

Expand Down
2 changes: 1 addition & 1 deletion recipe/session/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/supertokens/supertokens-golang/supertokens"
)

func SessionInit(config *models.TypeInput) supertokens.RecipeListFunction {
func Init(config *models.TypeInput) supertokens.RecipeListFunction {
return recipeInit(config)
}

Expand Down
2 changes: 1 addition & 1 deletion recipe/thirdparty/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type signInUpResponse struct {
User models.User
}

func ThirdPartyInit(config *models.TypeInput) supertokens.RecipeListFunction {
func Init(config *models.TypeInput) supertokens.RecipeListFunction {
return recipeInit(config)
}

Expand Down
2 changes: 1 addition & 1 deletion recipe/thirdpartyemailpassword/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/supertokens/supertokens-golang/supertokens"
)

func ThirdPartyEmailPasswordInit(config *models.TypeInput) supertokens.RecipeListFunction {
func Init(config *models.TypeInput) supertokens.RecipeListFunction {
return recipeInit(config)
}

Expand Down

0 comments on commit e431663

Please sign in to comment.