reorder to try to use go modules
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package pathway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
9
build.sh
Executable file
9
build.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
export GO111MODULE=off
|
||||||
|
|
||||||
|
echo go build -trimpath \
|
||||||
|
-ldflags="all=-s -w -buildid= -X main.version=$(cat VERSION) -X main.buildtime=$(date +%FT%T%z)" \
|
||||||
|
-o pathway \
|
||||||
|
src/*.go
|
||||||
7
cmd/go.mod
Normal file
7
cmd/go.mod
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
git.nxdomain.nl/mattijs/pathway@latest
|
||||||
|
)
|
||||||
48
cmd/main.go
Normal file
48
cmd/main.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"git.nxdomain.nl/mattijs/pathway"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// variables to set during build-time
|
||||||
|
debugging = ""
|
||||||
|
version = "0.0-undefined"
|
||||||
|
buildtime = "0000-00-00T00:00:00+0000"
|
||||||
|
)
|
||||||
|
|
||||||
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte("ok"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func emptyHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
info("pathway version:%s buildtime:%s", version, buildtime)
|
||||||
|
|
||||||
|
http.HandleFunc("/health", okHandler)
|
||||||
|
http.HandleFunc("/favicon.ico", emptyHandler)
|
||||||
|
http.HandleFunc("/robots.txt", emptyHandler)
|
||||||
|
http.HandleFunc("/", pathway.pathHandler)
|
||||||
|
|
||||||
|
err := http.ListenAndServe(":8080", nil)
|
||||||
|
if err != nil {
|
||||||
|
info("%s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func info(msg string, args ...interface{}) {
|
||||||
|
log.Printf("INFO | "+msg, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func debug(msg string, args ...interface{}) {
|
||||||
|
if len(debugging) > 0 {
|
||||||
|
log.Printf("DEBUG | "+msg, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package pathway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package pathway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
@@ -6,18 +6,19 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
// "nhooyr.io/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// variables to set during build-time
|
|
||||||
debugging = ""
|
|
||||||
version = "0.0-undefined"
|
|
||||||
buildtime = "0000-00-00T00:00:00+0000"
|
|
||||||
|
|
||||||
// actual business end of the device
|
// actual business end of the device
|
||||||
paths = &sync.Map{}
|
paths *sync.Map
|
||||||
|
debugging string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
paths = &sync.Map{}
|
||||||
|
}
|
||||||
|
|
||||||
// Transfer holds a single tranferable connection to be read
|
// Transfer holds a single tranferable connection to be read
|
||||||
type Transfer struct {
|
type Transfer struct {
|
||||||
reader io.ReadCloser
|
reader io.ReadCloser
|
||||||
@@ -57,7 +58,15 @@ func pathHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if h := r.Header.Get("Connection"); len(h) > 0 && strings.ToLower(h) == "upgrade" {
|
if h := r.Header.Get("Connection"); len(h) > 0 && strings.ToLower(h) == "upgrade" {
|
||||||
if h = r.Header.Get("Upgrade"); len(h) > 0 && strings.ToLower(h) == "websocket" {
|
if h = r.Header.Get("Upgrade"); len(h) > 0 && strings.ToLower(h) == "websocket" {
|
||||||
|
// c, err := websocket.Accept(w, r, nil)
|
||||||
|
// if err != nil {
|
||||||
|
// info("Websocket not accepted: %+s", err.Error())
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// defer c.Close(websocket.StatusInternalError, "the sky is falling")
|
||||||
info("Websocket connections not supported yet. Headers: %+v", r.Header)
|
info("Websocket connections not supported yet. Headers: %+v", r.Header)
|
||||||
|
// return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,29 +86,6 @@ func pathHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Write([]byte("ok"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func emptyHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
info("pathway version:%s buildtime:%s", version, buildtime)
|
|
||||||
|
|
||||||
http.HandleFunc("/health", okHandler)
|
|
||||||
http.HandleFunc("/favicon.ico", emptyHandler)
|
|
||||||
http.HandleFunc("/robots.txt", emptyHandler)
|
|
||||||
http.HandleFunc("/", pathHandler)
|
|
||||||
|
|
||||||
err := http.ListenAndServe(":8080", nil)
|
|
||||||
if err != nil {
|
|
||||||
info("%s", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func info(msg string, args ...interface{}) {
|
func info(msg string, args ...interface{}) {
|
||||||
log.Printf("INFO | "+msg, args...)
|
log.Printf("INFO | "+msg, args...)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package pathway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
Reference in New Issue
Block a user