Skip to content

Instantly share code, notes, and snippets.

View dickyaryag6's full-sized avatar

Dicky arya Kesuma dickyaryag6

  • Jakarta Metropolitan Area
  • 21:11 (UTC +07:00)
View GitHub Profile
@dickyaryag6
dickyaryag6 / main.go
Last active September 13, 2020 17:13
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
@dickyaryag6
dickyaryag6 / auth.go
Last active September 13, 2020 15:36
// 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
@dickyaryag6
dickyaryag6 / main.go
Last active September 13, 2020 17:14
func main() {
e := echo.New()
// Objek dari Session
sessions.SessionsStore = NewMemoryStore()
e.GET("/login", authentication.Login)
e.Start(":8000")
}
package sessions
import "errors"
type memoryStore struct {
sessions map[string]Session
}
func (m memoryStore) Get(id string) (Session, error) {
session, ok := m.sessions[id]
package sessions
var SessionsStore Store
type Session struct {
Name string `json:"name"`
UserID int `json:"userID"`
}
type Store interface {
CREATE DATABASE sekolah;
\c sekolah;
CREATE DATABASE company;