commit 375d0a03a961229d50652c97857c7f29cf3b9ebc Author: hupeh Date: Mon Jun 3 18:50:12 2024 +0800 first edition diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de7f3d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +.vscode +tmp \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..93ebcf7 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +set -euxo pipefail + +mkdir -p "$(pwd)/functions" +GOBIN=$(pwd)/functions go install ./... +chmod +x "$(pwd)"/functions/* +go env \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..30d0070 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module app + +go 1.22.1 + +require github.com/apex/gateway v1.1.2 + +require ( + github.com/aws/aws-lambda-go v1.17.0 // indirect + github.com/pkg/errors v0.9.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..577534a --- /dev/null +++ b/go.sum @@ -0,0 +1,27 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/apex/gateway v1.1.2 h1:OWyLov8eaau8YhkYKkRuOAYqiUhpBJalBR1o+3FzX+8= +github.com/apex/gateway v1.1.2/go.mod h1:AMTkVbz5u5Hvd6QOGhhg0JUrNgCcLVu3XNJOGntdoB4= +github.com/aws/aws-lambda-go v1.17.0 h1:Ogihmi8BnpmCNktKAGpNwSiILNNING1MiosnKUfU8m0= +github.com/aws/aws-lambda-go v1.17.0/go.mod h1:FEwgPLE6+8wcGBTe5cJN3JWurd1Ztm9zN4jsXsjzKKw= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk= +github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk= +github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +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= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c h1:grhR+C34yXImVGp7EzNk+DTIk+323eIUWOmEevy6bDo= +gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..6dd627e --- /dev/null +++ b/main.go @@ -0,0 +1,73 @@ +package main + +import ( + "bytes" + "flag" + "fmt" + "net/http" + "strings" + + "github.com/apex/gateway" +) + +var ( + port = flag.Int("port", -1, "specify a port") +) + +func main() { + flag.Parse() + + listen := gateway.ListenAndServe + + addr := "n/a" + if *port != -1 { + addr = fmt.Sprintf(":%d", *port) + listen = http.ListenAndServe + } + + listen(addr, http.HandlerFunc(serve)) +} + +func serve(w http.ResponseWriter, r *http.Request) { + parts := strings.Split(r.RequestURI, "/")[1:] + + w.Header().Set("content-type", "text/html") + + if len(parts) != 1 { + w.Write(notfound()) + } else { + w.Write(module(parts[0])) + } +} + +func notfound() []byte { + return []byte(` + + + + + zestack.dev + + + https://slim.zestack.dev + +`) +} + +func module(name string) []byte { + bts := []byte(` + + + + + + +{} - zestack.dev + + + https://slim.zestack.dev + +`) + + return bytes.ReplaceAll(bts, []byte("{}"), []byte(name)) +} diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..7bfa189 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,8 @@ +[build] + command = "./build.sh" + functions = "functions" + publish = "dist" + +[context.production.environment] + GOOS = "linux" + GOARCH = "amd64" \ No newline at end of file