Private
Public Access
0
0

reorder to try to use go modules

This commit is contained in:
teizz
2021-09-30 12:26:15 +02:00
parent cd0673777f
commit 979ef108f4
9 changed files with 86 additions and 33 deletions

View File

@@ -1,4 +1,4 @@
package main
package pathway
import (
"io"

9
build.sh Executable file
View 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
View File

@@ -0,0 +1,7 @@
module main
go 1.16
require (
git.nxdomain.nl/mattijs/pathway@latest
)

48
cmd/main.go Normal file
View 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...)
}
}

View File

@@ -1,4 +1,4 @@
package main
package pathway
import (
"io"

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module git.nxdomain.nl/mattijs/pathway
go 1.16

View File

@@ -1,4 +1,4 @@
package main
package pathway
import (
"io"
@@ -6,18 +6,19 @@ import (
"net/http"
"strings"
"sync"
// "nhooyr.io/websocket"
)
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
paths = &sync.Map{}
paths *sync.Map
debugging string
)
func init() {
paths = &sync.Map{}
}
// Transfer holds a single tranferable connection to be read
type Transfer struct {
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("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)
// 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{}) {
log.Printf("INFO | "+msg, args...)
}

View File

@@ -1,4 +1,4 @@
package main
package pathway
import (
"io"