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 models | |
import ( | |
_ "github.com/jinzhu/gorm/dialects/postgres" | |
"github.com/jinzhu/gorm" | |
"os" | |
"github.com/joho/godotenv" | |
"fmt" | |
) |
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 models | |
import ( | |
"github.com/dgrijalva/jwt-go" | |
u "lens/utils" | |
"strings" | |
"github.com/jinzhu/gorm" | |
"os" | |
"golang.org/x/crypto/bcrypt" | |
) |
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 app | |
import ( | |
"net/http" | |
u "lens/utils" | |
"strings" | |
"go-contacts/models" | |
jwt "github.com/dgrijalva/jwt-go" | |
"os" | |
"context" |
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 utils | |
import ( | |
"encoding/json" | |
"net/http" | |
) | |
func Message(status bool, message string) (map[string]interface{}) { | |
return map[string]interface{} {"status" : status, "message" : message} | |
} |
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
#!/bin/bash | |
# Generate a random uuid to use as a docker tag | |
NEW_UUID=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) | |
# build binary | |
export GOOS=linux && go build -o sample-auth main.go | |
# build docker image | |
docker build -t "sample-auth" . | |
# tag image | |
docker tag sample-auth localhost:5010/sample-auth:${NEW_UUID} | |
# push image to registry running at localhost:5010 |
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
version: "3" | |
services: | |
sample-server: | |
build: ./ | |
container_name: sample-server | |
restart: on-failure | |
environment: | |
- PORT=5008 | |
ports: |
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
FROM alpine:3.2 | |
RUN apk update && apk add --no-cache ca-certificates | |
ADD . /app | |
WORKDIR /app | |
RUN chmod +x /app/sample-auth | |
ENTRYPOINT [ "/app/sample-auth" ] |
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
func (srv *tokenServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
username, password, ok := r.BasicAuth() | |
if !ok { | |
http.Error(w, "auth credentials not found", http.StatusUnauthorized) | |
return | |
} | |
// compare username and password against your datasets | |
// our example only allows foo:bar | |
if username != "foo" || password != "bar" { | |
http.Error(w, "invalid auth credentials", http.StatusUnauthorized) |
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
type Option struct { | |
issuer, typ, name, account, service string | |
actions []string // requested actions | |
} | |
type Token struct { | |
Token string `json:"token"` | |
AccessToken string `json:"access_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
import ( | |
"github.com/docker/libtrust" | |
"crypto/tls" | |
"crypto/x509" | |
) | |
type tokenServer struct { | |
privateKey libtrust.PrivateKey | |
pubKey libtrust.PublicKey | |
crt, key string | |
} |
NewerOlder