Skip to content

Instantly share code, notes, and snippets.

View dickyaryag6's full-sized avatar

Dicky arya Kesuma dickyaryag6

  • Jakarta Metropolitan Area
  • 03:30 (UTC +07:00)
View GitHub Profile
CREATE DATABASE company;
CREATE DATABASE sekolah;
\c sekolah;
package sessions
var SessionsStore Store
type Session struct {
Name string `json:"name"`
UserID int `json:"userID"`
}
type Store interface {
package sessions
import "errors"
type memoryStore struct {
sessions map[string]Session
}
func (m memoryStore) Get(id string) (Session, error) {
session, ok := m.sessions[id]
@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")
}
@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: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 / main.go
Last active September 13, 2020 17:32
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
package sessions
import (
"encoding/json"
"fmt"
"github.com/go-redis/redis"
"log"
"time"
)
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",