Skip to content

Instantly share code, notes, and snippets.

View gufranmirza's full-sized avatar

Gufran Mirza gufranmirza

View GitHub Profile
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 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)
package main
import (
"time"
"github.com/dgrijalva/jwt-go"
)
func generateTokenPair() (map[string]string, error) {
// Create token
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,
package main
import (
"github.com/labstack/echo/middleware"
)
var IsLoggedIn = middleware.JWTWithConfig(middleware.JWTConfig{
SigningKey: []byte("secret"),
})
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!")
})
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
// main.go
package main
import (
"fmt"
"encoding/json"
"log"
"net/http"
"github.com/gorilla/mux"
"io/ioutil"
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";
import (
//...
// The libn/pq driver is used for postgres
_ "github.com/lib/pq"
//...
)
func main(){
// ...
connString := "dbname=<your main db name> sslmode=disable"