This file contains 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
c := cron.New() | |
c.AddFunc("30 * * * *", func() { | |
fmt.Println("Every hour on the half hour") | |
}) | |
c.AddFunc("30 3-6,20-23 * * *", func() { | |
fmt.Println(".. in the range 3-6am, 8-11pm") | |
}) |
This file contains 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
// This is the api to refresh tokens | |
// Most of the code is taken from the jwt-go package's sample codes | |
// https://godoc.org/github.com/dgrijalva/jwt-go#example-Parse--Hmac | |
func (h *handler) token(c echo.Context) error { | |
type tokenReqBody struct { | |
RefreshToken string `json:"refresh_token"` | |
} | |
tokenReq := tokenReqBody{} | |
c.Bind(&tokenReq) |
This file contains 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 main | |
import ( | |
"time" | |
"github.com/dgrijalva/jwt-go" | |
) | |
func generateTokenPair() (map[string]string, error) { | |
// Create token |
This file contains 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
refreshToken := jwt.New(jwt.SigningMethodHS256) | |
rtClaims := refreshToken.Claims.(jwt.MapClaims) | |
rtClaims["sub"] = 1 | |
rtClaims["exp"] = time.Now().Add(time.Hour * 24).Unix() | |
rt, err := refreshToken.SignedString([]byte("secret")) | |
if err != nil { | |
return err | |
} | |
return c.JSON(http.StatusOK, map[string]string{ | |
"access_token": t, |
This file contains 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 main | |
import ( | |
"github.com/labstack/echo/middleware" | |
) | |
var IsLoggedIn = middleware.JWTWithConfig(middleware.JWTConfig{ | |
SigningKey: []byte("secret"), | |
}) |
This file contains 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 main | |
import ( | |
"net/http" | |
"github.com/labstack/echo" | |
) | |
func main() { | |
e := echo.New() | |
e.GET("/", func(c echo.Context) error { | |
return c.String(http.StatusOK, "Hello, World!") | |
}) |
This file contains 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 main | |
import ( | |
"net/http" | |
"time" | |
"github.com/dgrijalva/jwt-go" | |
"github.com/labstack/echo" | |
) | |
type handler struct{} | |
// Most of the code is taken from the echo guide | |
// https://echo.labstack.com/cookbook/jwt |
This file contains 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
// main.go | |
package main | |
import ( | |
"fmt" | |
"encoding/json" | |
"log" | |
"net/http" | |
"github.com/gorilla/mux" | |
"io/ioutil" |
This file contains 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
import express from "express"; | |
import expressGraphQL from "express-graphql"; | |
import mongoose from "mongoose"; | |
import bodyParser from "body-parser"; | |
import cors from "cors"; | |
const app = express(); | |
const PORT = process.env.PORT || "4000"; | |
const db = "mongodb://127.0.0.1/temp"; |
This file contains 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
import ( | |
//... | |
// The libn/pq driver is used for postgres | |
_ "github.com/lib/pq" | |
//... | |
) | |
func main(){ | |
// ... | |
connString := "dbname=<your main db name> sslmode=disable" |