first edition

main
熊二 6 months ago
commit 375d0a03a9
  1. 3
      .gitignore
  2. 6
      build.sh
  3. 10
      go.mod
  4. 27
      go.sum
  5. 73
      main.go
  6. 8
      netlify.toml

3
.gitignore vendored

@ -0,0 +1,3 @@
.idea
.vscode
tmp

@ -0,0 +1,6 @@
set -euxo pipefail
mkdir -p "$(pwd)/functions"
GOBIN=$(pwd)/functions go install ./...
chmod +x "$(pwd)"/functions/*
go env

@ -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
)

@ -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=

@ -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(`<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>zestack.dev</title>
</head>
<body>
<a href="https://slim.zestack.dev">https://slim.zestack.dev</a>
</body>
</html>`)
}
func module(name string) []byte {
bts := []byte(`<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<meta name="go-import" content="zestack.dev/{} git https://github.com/zestack/{}">
<meta name="go-source" content="zestack.dev/{} https://github.com/zestack/{} https://github.com/zestack/{}/tree/master{/dir} https://github.com/zestack/{}/blob/master{/dir}/{file}#L{line}">
<title>{} - zestack.dev</title>
</head>
<body>
<a href="https://slim.zestack.dev">https://slim.zestack.dev</a>
</body>
</html>`)
return bytes.ReplaceAll(bts, []byte("{}"), []byte(name))
}

@ -0,0 +1,8 @@
[build]
command = "./build.sh"
functions = "functions"
publish = "dist"
[context.production.environment]
GOOS = "linux"
GOARCH = "amd64"
Loading…
Cancel
Save