Browse Source

0.0.1

master 0.0.1
Atridad Lahiji 2 months ago
commit
10d96811cb
  1. 3
      .env.example
  2. 2
      .gitignore
  3. 2
      README.md
  4. 29
      build.sh
  5. 12
      frontend/index.html
  6. 13
      go.mod
  7. 32
      go.sum
  8. 66
      main.go

3
.env.example

@ -0,0 +1,3 @@
ENDPOINT="https://google.com"
AUTH_TOKEN=
METHOD=POST

2
.gitignore

@ -0,0 +1,2 @@
bin/
.env

2
README.md

@ -0,0 +1,2 @@
# MiddleWhere
This is a dumb little project I made for the sole purpose of exposing private endpoints to the public via a middleman service. This is written in golang and has been built for macos and linux (both on x86 64-bit)

29
build.sh

@ -0,0 +1,29 @@
#!/bin/bash
VERSION="0.0.1"
export OLD_GOOS=$(go env GOOS)
export OLD_GOARCH=$(go env GOARCH)
mkdir bin
mkdir bin/$VERSION
# buid for macos x86 64-bit
export GOOS=darwin
export GOARCH=amd64
mkdir bin/$VERSION/$(go env GOOS)-$(go env GOARCH)
cp .env.example ./bin/$VERSION/$(go env GOOS)-$(go env GOARCH)/.env.example
go build -o ./bin/$VERSION/$(go env GOOS)-$(go env GOARCH)/middlewhere-$VERSION-$(go env GOOS)-$(go env GOARCH)
$(go env GOPATH)/bin/rice append --exec ./bin/$VERSION/$(go env GOOS)-$(go env GOARCH)/middlewhere-$VERSION-$(go env GOOS)-$(go env GOARCH)
tar -czvf ./bin/$VERSION/$VERSION-$(go env GOOS)-$(go env GOARCH).tar.gz ./bin/$VERSION/$(go env GOOS)-$(go env GOARCH)
# buid for linux x86 64-bit
export GOOS=linux
export GOARCH=amd64
mkdir bin/$VERSION/$(go env GOOS)-$(go env GOARCH)
cp .env.example ./bin/$VERSION/$(go env GOOS)-$(go env GOARCH)/.env.example
go build -o ./bin/$VERSION/$(go env GOOS)-$(go env GOARCH)/middlewhere-$VERSION-$(go env GOOS)-$(go env GOARCH)
$(go env GOPATH)/bin/rice append --exec ./bin/$VERSION/$(go env GOOS)-$(go env GOARCH)/middlewhere-$VERSION-$(go env GOOS)-$(go env GOARCH)
tar -czvf ./bin/$VERSION/$VERSION-$(go env GOOS)-$(go env GOARCH).tar.gz ./bin/$VERSION/$(go env GOOS)-$(go env GOARCH)

12
frontend/index.html

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MiddleWhere</title>
</head>
<body>
MiddleWhere
</body>
</html>

13
go.mod

@ -0,0 +1,13 @@
module git.atrilahiji.dev/atrilahiji/eleutheriapay
go 1.16
require (
github.com/GeertJohan/go.rice v1.0.2 // indirect
github.com/ajstarks/svgo v0.0.0-20200725142600-7a3c8b57fecb // indirect
github.com/campoy/svg-badge v0.0.0-20180116034456-40c38fcad9f6 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/stripe/stripe-go/v72 v72.37.0 // indirect
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
)

32
go.sum

@ -0,0 +1,32 @@
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
github.com/ajstarks/svgo v0.0.0-20200725142600-7a3c8b57fecb h1:EVl3FJLQCzSbgBezKo/1A4ADnJ4mtJZ0RvnNzDJ44nY=
github.com/ajstarks/svgo v0.0.0-20200725142600-7a3c8b57fecb/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/campoy/svg-badge v0.0.0-20180116034456-40c38fcad9f6 h1:tqkfnr9GEZzMyWtQKvgPwWvWxH8RCMA+GeNylbYYEb0=
github.com/campoy/svg-badge v0.0.0-20180116034456-40c38fcad9f6/go.mod h1:kDWVB5nIXF847uNfomMkNoV4QEdH0q0JwMPQvgsvsLI=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stripe/stripe-go/v72 v72.37.0/go.mod h1:QwqJQtduHubZht9mek5sds9CtQcKFdsykV9ZepRWwo0=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

66
main.go

@ -0,0 +1,66 @@
package main
import (
"io/ioutil"
"log"
"net/http"
"os"
rice "github.com/GeertJohan/go.rice"
"github.com/joho/godotenv"
)
func loadEnv() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("Health Check"))
}
func webHookHandler(w http.ResponseWriter, r *http.Request) {
// Create a Bearer string by appending string access token
// Create a new request using http
req, err := http.NewRequest(os.Getenv("METHOD"), os.Getenv("ENDPOINT"), nil)
// add authorization header to the req
authToken := os.Getenv("AUTH_TOKEN")
if authToken != "" {
var bearer = "Bearer " + authToken
req.Header.Add("Authorization", bearer)
}
// Send req using http Client
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Println("Error on response.\n[ERROR] -", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("Error while reading the response bytes:", err)
}
log.Println(string([]byte(body)))
}
func main() {
loadEnv()
http.Handle("/", http.FileServer(rice.MustFindBox("frontend").HTTPBox()))
http.HandleFunc("/api/healthcheck", healthCheckHandler)
http.HandleFunc("/api/triggerWebHook", webHookHandler)
log.Println("Listening on :3000...")
err := http.ListenAndServe(":3000", nil)
if err != nil {
log.Fatal(err)
}
}
Loading…
Cancel
Save