This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE DATABASE company; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE DATABASE sekolah; | |
| \c sekolah; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package sessions | |
| var SessionsStore Store | |
| type Session struct { | |
| Name string `json:"name"` | |
| UserID int `json:"userID"` | |
| } | |
| type Store interface { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package sessions | |
| import "errors" | |
| type memoryStore struct { | |
| sessions map[string]Session | |
| } | |
| func (m memoryStore) Get(id string) (Session, error) { | |
| session, ok := m.sessions[id] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func main() { | |
| e := echo.New() | |
| // Objek dari Session | |
| sessions.SessionsStore = NewMemoryStore() | |
| e.GET("/login", authentication.Login) | |
| e.Start(":8000") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // struct that will be encoded to a JWT. | |
| type JwtClaims struct { | |
| Name string `json:"name"` | |
| jwt.StandardClaims | |
| } | |
| func Login(c echo.Context) error { | |
| name := c.FormValue("name") | |
| pass := c.FormValue("pass") | |
| userID := 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func hello(c echo.Context) error { | |
| cookie, err := c.Cookie("JWTCookie") | |
| //if cookie doesnt exist | |
| if err != nil { | |
| c.String(http.StatusUnauthorized, "Not Authorized") | |
| return err | |
| } | |
| //get jwt token | |
| tokenString := cookie.Value | |
| //get session data from redis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func main() { | |
| e := echo.New() | |
| //sessions.SessionsStore = NewMemoryStore() | |
| sessions.SessionsStore = sessions.NewRedisStore() | |
| e.GET("/login", authentication.Login) | |
| g := e.Group("/hello") | |
| //Use Middleware to verify JWT Token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package sessions | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "github.com/go-redis/redis" | |
| "log" | |
| "time" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ( | |
| spreadsheetId string = "17_V0gRP4z4VE5dHT2u5m44QBCIAUD_ov2i" | |
| sheetKey Key = Key{ | |
| Type: "service_account", | |
| ProjectID: "sheet-projec", | |
| PrivateKeyID: "xxxxx", | |
| PrivateKey: "-----BEGIN PRIVATE KEY-----\xxxxx=\n-----END PRIVATE KEY-----\n", | |
| ClientEmail: "sheet-service-account@xxxxx.iam.gserviceaccount.com", | |
| ClientID: "xxxxx", |
OlderNewer