Use pkger for static assets
This commit is contained in:
parent
d65499c4aa
commit
4e850b5103
|
@ -20,7 +20,8 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
go: ["1.14"]
|
||||
name: Go ${{ matrix.go }}
|
||||
pkger: [false, true]
|
||||
name: Go ${{ matrix.go }} (${{ matrix.pkger && 'static' || 'live' }})
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -39,6 +40,12 @@ jobs:
|
|||
- name: Download Go modules
|
||||
run: go mod download
|
||||
|
||||
- name: Run pkger
|
||||
if: ${{ matrix.pkger }}
|
||||
run: |
|
||||
go run github.com/markbates/pkger/cmd/pkger list
|
||||
go run github.com/markbates/pkger/cmd/pkger -o internal/pkger
|
||||
|
||||
- name: Run tests
|
||||
run: go test -race -covermode=atomic -coverprofile=coverage.txt ./...
|
||||
|
||||
|
|
|
@ -20,3 +20,5 @@ codies
|
|||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
pkged.go
|
||||
|
|
|
@ -23,14 +23,15 @@ RUN go mod download
|
|||
# Manually copying the required files to make this image's cache only include Go code.
|
||||
COPY *.go ./
|
||||
COPY ./internal ./internal
|
||||
COPY --from=JS_BUILD /frontend/build ./frontend/build
|
||||
RUN go run github.com/markbates/pkger/cmd/pkger list && \
|
||||
go run github.com/markbates/pkger/cmd/pkger -o internal/pkger
|
||||
|
||||
ARG version
|
||||
RUN go build -ldflags="-X github.com/zikaeroh/codies/internal/version.version=${version}" .
|
||||
|
||||
# TODO: Use distroless/static and statically compile above. (https://golang.org/issue/26492)
|
||||
FROM gcr.io/distroless/base:nonroot
|
||||
WORKDIR /codies
|
||||
COPY --from=GO_BUILD /codies/codies ./codies
|
||||
COPY --from=JS_BUILD /frontend/build ./frontend/build
|
||||
ENTRYPOINT [ "/codies/codies", "--prod" ]
|
||||
COPY --from=GO_BUILD /codies/codies /codies
|
||||
ENTRYPOINT [ "/codies", "--prod" ]
|
||||
EXPOSE 5000
|
||||
|
|
4
go.mod
4
go.mod
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/gofrs/uuid v3.3.0+incompatible
|
||||
github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4
|
||||
github.com/mailru/easyjson v0.7.1
|
||||
github.com/mjibson/esc v0.2.0
|
||||
github.com/markbates/pkger v0.17.0
|
||||
github.com/posener/ctxutil v1.0.0
|
||||
github.com/prometheus/client_golang v1.6.0
|
||||
github.com/speps/go-hashids v2.0.0+incompatible
|
||||
|
@ -17,3 +17,5 @@ require (
|
|||
gotest.tools/v3 v3.0.2
|
||||
nhooyr.io/websocket v1.8.6
|
||||
)
|
||||
|
||||
replace github.com/markbates/pkger => github.com/zikaeroh/pkger v0.17.1-0.20200604025301-dceb832975ba
|
||||
|
|
8
go.sum
8
go.sum
|
@ -31,6 +31,8 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
|
|||
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
|
||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
|
||||
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
|
||||
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0=
|
||||
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
|
||||
github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
|
||||
|
@ -82,8 +84,6 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
|
|||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mjibson/esc v0.2.0 h1:k96hdaR9Z+nMcnDwNrOvhdBqtjyMrbVyxLpsRCdP2mA=
|
||||
github.com/mjibson/esc v0.2.0/go.mod h1:9Hw9gxxfHulMF5OJKCyhYD7PzlSdhzXyaGEBRPH1OPs=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
|
@ -133,6 +133,8 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
|||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/zikaeroh/pkger v0.17.1-0.20200604025301-dceb832975ba h1:t0aP/yT6220rbPXYRf4ASwgWkynUvy+SGQqR6jNzutc=
|
||||
github.com/zikaeroh/pkger v0.17.1-0.20200604025301-dceb832975ba/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
|
||||
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
|
||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
|
@ -184,12 +186,14 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
|
|||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E=
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// Package pkger wraps pkger to ensure a common package contains the embedded data.
|
||||
// It abuses the fact that pkger's static analysis only cares that the package name matches.
|
||||
package pkger
|
||||
|
||||
import "github.com/markbates/pkger"
|
||||
|
||||
type Dir = pkger.Dir
|
|
@ -1,352 +0,0 @@
|
|||
// Code generated by "esc -o=esc.go -pkg=static -ignore=^(static|esc)\.go$ -modtime=0 -private ."; DO NOT EDIT.
|
||||
|
||||
package static
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type _escLocalFS struct{}
|
||||
|
||||
var _escLocal _escLocalFS
|
||||
|
||||
type _escStaticFS struct{}
|
||||
|
||||
var _escStatic _escStaticFS
|
||||
|
||||
type _escDirectory struct {
|
||||
fs http.FileSystem
|
||||
name string
|
||||
}
|
||||
|
||||
type _escFile struct {
|
||||
compressed string
|
||||
size int64
|
||||
modtime int64
|
||||
local string
|
||||
isDir bool
|
||||
|
||||
once sync.Once
|
||||
data []byte
|
||||
name string
|
||||
}
|
||||
|
||||
func (_escLocalFS) Open(name string) (http.File, error) {
|
||||
f, present := _escData[path.Clean(name)]
|
||||
if !present {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
return os.Open(f.local)
|
||||
}
|
||||
|
||||
func (_escStaticFS) prepare(name string) (*_escFile, error) {
|
||||
f, present := _escData[path.Clean(name)]
|
||||
if !present {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
var err error
|
||||
f.once.Do(func() {
|
||||
f.name = path.Base(name)
|
||||
if f.size == 0 {
|
||||
return
|
||||
}
|
||||
var gr *gzip.Reader
|
||||
b64 := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(f.compressed))
|
||||
gr, err = gzip.NewReader(b64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
f.data, err = ioutil.ReadAll(gr)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (fs _escStaticFS) Open(name string) (http.File, error) {
|
||||
f, err := fs.prepare(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f.File()
|
||||
}
|
||||
|
||||
func (dir _escDirectory) Open(name string) (http.File, error) {
|
||||
return dir.fs.Open(dir.name + name)
|
||||
}
|
||||
|
||||
func (f *_escFile) File() (http.File, error) {
|
||||
type httpFile struct {
|
||||
*bytes.Reader
|
||||
*_escFile
|
||||
}
|
||||
return &httpFile{
|
||||
Reader: bytes.NewReader(f.data),
|
||||
_escFile: f,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *_escFile) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *_escFile) Readdir(count int) ([]os.FileInfo, error) {
|
||||
if !f.isDir {
|
||||
return nil, fmt.Errorf(" escFile.Readdir: '%s' is not directory", f.name)
|
||||
}
|
||||
|
||||
fis, ok := _escDirs[f.local]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(" escFile.Readdir: '%s' is directory, but we have no info about content of this dir, local=%s", f.name, f.local)
|
||||
}
|
||||
limit := count
|
||||
if count <= 0 || limit > len(fis) {
|
||||
limit = len(fis)
|
||||
}
|
||||
|
||||
if len(fis) == 0 && count > 0 {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
return fis[0:limit], nil
|
||||
}
|
||||
|
||||
func (f *_escFile) Stat() (os.FileInfo, error) {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (f *_escFile) Name() string {
|
||||
return f.name
|
||||
}
|
||||
|
||||
func (f *_escFile) Size() int64 {
|
||||
return f.size
|
||||
}
|
||||
|
||||
func (f *_escFile) Mode() os.FileMode {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (f *_escFile) ModTime() time.Time {
|
||||
return time.Unix(f.modtime, 0)
|
||||
}
|
||||
|
||||
func (f *_escFile) IsDir() bool {
|
||||
return f.isDir
|
||||
}
|
||||
|
||||
func (f *_escFile) Sys() interface{} {
|
||||
return f
|
||||
}
|
||||
|
||||
// _escFS returns a http.Filesystem for the embedded assets. If useLocal is true,
|
||||
// the filesystem's contents are instead used.
|
||||
func _escFS(useLocal bool) http.FileSystem {
|
||||
if useLocal {
|
||||
return _escLocal
|
||||
}
|
||||
return _escStatic
|
||||
}
|
||||
|
||||
// _escDir returns a http.Filesystem for the embedded assets on a given prefix dir.
|
||||
// If useLocal is true, the filesystem's contents are instead used.
|
||||
func _escDir(useLocal bool, name string) http.FileSystem {
|
||||
if useLocal {
|
||||
return _escDirectory{fs: _escLocal, name: name}
|
||||
}
|
||||
return _escDirectory{fs: _escStatic, name: name}
|
||||
}
|
||||
|
||||
// _escFSByte returns the named file from the embedded assets. If useLocal is
|
||||
// true, the filesystem's contents are instead used.
|
||||
func _escFSByte(useLocal bool, name string) ([]byte, error) {
|
||||
if useLocal {
|
||||
f, err := _escLocal.Open(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err := ioutil.ReadAll(f)
|
||||
_ = f.Close()
|
||||
return b, err
|
||||
}
|
||||
f, err := _escStatic.prepare(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f.data, nil
|
||||
}
|
||||
|
||||
// _escFSMustByte is the same as _escFSByte, but panics if name is not present.
|
||||
func _escFSMustByte(useLocal bool, name string) []byte {
|
||||
b, err := _escFSByte(useLocal, name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// _escFSString is the string version of _escFSByte.
|
||||
func _escFSString(useLocal bool, name string) (string, error) {
|
||||
b, err := _escFSByte(useLocal, name)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// _escFSMustString is the string version of _escFSMustByte.
|
||||
func _escFSMustString(useLocal bool, name string) string {
|
||||
return string(_escFSMustByte(useLocal, name))
|
||||
}
|
||||
|
||||
var _escData = map[string]*_escFile{
|
||||
|
||||
"/codenames/README.md": {
|
||||
name: "README.md",
|
||||
local: "codenames/README.md",
|
||||
size: 96,
|
||||
modtime: 0,
|
||||
compressed: `
|
||||
H4sIAAAAAAAC/xTL0QnCQAwG4HenyAJtsIJg53CBePf3WmzMkZxkfXGA77kjQNtxIkgcFPb1gkqbm660
|
||||
j9FjZc7M+WXitYmiAe+5mPJfdWng6+2+PBYuVvERRUxpXqfziHH5BQAA//+Xdl6cYAAAAA==
|
||||
`,
|
||||
},
|
||||
|
||||
"/codenames/default.txt": {
|
||||
name: "default.txt",
|
||||
local: "codenames/default.txt",
|
||||
size: 2482,
|
||||
modtime: 0,
|
||||
compressed: `
|
||||
H4sIAAAAAAAC/ySWUXajSq+F3/coeioGx3F3bIdrfNrrPMqFDDoUJa6oipse/b9E3uIVISTtT1scNcb1
|
||||
pdrhzjHioJpx4dePf9VGtLNJ6lFrsYxbeTAalZRxo0fkjDbKjD1lxt4kRpx40oTK87TBmBMOJIabWhjQ
|
||||
Zg88Uw4DfprHRQ0jDkYpMHZlyUZRCCeZtCySGG02pgnvUb8Yl2IL48SzcRioJDSRVtxU84CdTajYptIR
|
||||
9kKTpg73gSKj1kkCzjRNHve+1dTQsuAsyyKR/cdWvs5oBuUkf3Ame0R/Oz2fOEhfzMNsRM0pUzG0A3X6
|
||||
wkGWAbXmrAlv/Tpn3AamzIY2+LsPFCNuRt6kWmDsJeniCSof1tlbvBUbefVXBs+VslHIqEy6nnHVhySc
|
||||
PK6JPryKUoeD2PbXiEp1Qk0Z7aAZbZGMetCgW+xVS+TsE2cLxVacVRMunHGi1+pFUuYYJTN2qeeIdpaO
|
||||
De9sE6XVSx7RiKv1sTFg5PWaK66OROpKyGo+moyq9JFx/w7nHIYyozFeFk+bGHe1Cbs4L6hcnIYcE/nP
|
||||
E18pjJxRm3o0U8Tub2YXbd70MQpDyYyjZo4us61oNXbChiutaHTJm7KB0f5/IXPIlgUVZdzpi1GToZ1K
|
||||
30c2vKU++hRro2XAjST6/zsc1RJqmiVTxIEdyT2HEVV5PikqzhJMl6Az4xdn7EsYcfXyb0aScBCOHd41
|
||||
drhJGFEP/vD/FeetzSYj44NST6bqExkZbRBOWZbsJW20DzTyMrM3cJfU4UM6vE0PWpbVUfC91Mx4Ny2p
|
||||
w97omXGkCXcynLUsvAHKhnr4LkESodKY0c6a0QglRVNmiWiiZpxEExqNEhhHpg4nydvjmgJbxrn0+E2h
|
||||
lAm7HMmL9V7ohfa1Cd2O6xKMZjacaNm4Lw/6sZcvNuyeJoEc3CVLwP5F9sSJZpzk6WImXn3oCy+DMv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==
|
||||
`,
|
||||
},
|
||||
|
||||
"/codenames/duet.txt": {
|
||||
name: "duet.txt",
|
||||
local: "codenames/duet.txt",
|
||||
size: 2634,
|
||||
modtime: 0,
|
||||
compressed: `
|
||||
H4sIAAAAAAAC/ySWQXbrOg5E57WKrKD3YMmJ/RM7X99yx6d7BlOwxBZF6IFk9PxW3wfMxAMdGQJRVRfc
|
||||
a1nQqB8YNxol4t/Rf7Mmn584+oxdmtBQStilrBKpZOwlBHyyfjNaITehYVrQryIRrZSY9YlPSYwPH8eX
|
||||
neapKPpMy4rWfholH3FieuBacrEiKeNUoptwnUocWNFJpizYc5rxd/QS8Rp4nShm7KKbRNHKdpcn3oLI
|
||||
gLNMtM3oKWZC57ObWNGQ3tkVtk9le9DPlDnhXNLMme1BpBU9DUNgHDh6xpl0Rj9JCdbFQb5ZoyjOFL0r
|
||||
ytjFPPGCI4UgG3PEJ29ZIhp7IBFvvhZrlR4Zh0DOs6KlmXGhjCvFGU3wcUC/evUZLd0Do99sLq8+psw+
|
||||
4mhqtPpMmQIOTIoPnxI63tDJZo1di+bAaMhJRD+xBnEz+l+FTC6RGRf6I4q9cko+jqawm23yf3zA1Ur2
|
||||
uX668bOPHh1HXEzXdlKf8kIJl3K/1yk+cZY6vw+r8SYjLjR4sUPe0Upk9HMJAbeJObiJvOJ1HNGUnFlx
|
||||
Y+VNwgPtxKpPdJQ9x4y9PtkapK32Jynhjb/rByNFQifBpwkfUTI68jGjz6ILDhIGb8dN6LypgHYyP50l
|
||||
cUJPGxr9afdCPuAiK6PPymxlBrS0Znv9ZsV3v9nE1pzQyepEI1pKNtmencTBJrXgb0o+4cwp4Ww67L4p
|
||||
UHQT48q/KaEv5uZ62EtJGTc7UJ+ZA15t0E5tsE2JM1qKjC+OJeFEQzV60WRNWH+ftEpgU7SMpNh7ZZdF
|
||||
sXNsVShb1oqb2XzDqb6SZoufDmhKuKNhC1HvSNmpbPhrDCK4lt88iDWTJ1wsqz5Zt40yDbiwEx2wN+sc
|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2T652sjwVowXkn4VnwU3XwdQheSIA6mN7kY+2w62j0s2w4SAU1nu
|
||||
rP+rqOTBO1vTRtlQOP1Q+lex9HdMJskP0XhAv9i/W1nWYudpZbNXYqkrZ5DNbjbZmuiNEYe6dOsWcFyp
|
||||
sVtVIr68BLZbnNg5TZp3MY4dK/bbnwEcaSPvsd9IH+iMh2cavfMUjckpoy22zJtyt0vEzTLw/wAAAP//
|
||||
h4maTUoKAAA=
|
||||
`,
|
||||
},
|
||||
|
||||
"/codenames/undercover.txt": {
|
||||
name: "undercover.txt",
|
||||
local: "codenames/undercover.txt",
|
||||
size: 2447,
|
||||
modtime: 0,
|
||||
compressed: `
|
||||
H4sIAAAAAAAC/yyW33qqwA7F79e7nIcoWHW3ajnCrtcBIuRjmLDnT5U+/fmC56b2E1mZJL+szFFDZNSU
|
||||
PeGoOnFAnVQdzprTiEZzN/b68Kg9TYzbKHHiFZV0k2McNTJOPLDvUbgcR+ykm1BqN+HNdTqqM+1IA6Pi
|
||||
7qUeSIYxodbAaHRF4aibTDnZj4Joj9LC4iNLxygCYUczoxxNu5DUjag7e7semZdNccGZUgocI5pA4lGo
|
||||
7y3qTdhzQMVeIvY5hBUfusZkUm/L4jiiVN/rjEIiPzM5HNUxau4CJworruqcxZAF+8A0WYB5wV4Dx0k8
|
||||
buLt3Iz358JBZvYJHzr6qB4FefKE0tGMwukDBTmn6lHzzB5XHgKnl/jCAUedOWSPJsiMggJuqj0q6nvH
|
||||
KPUxSHCbNkry23cyUOCU/v8fPr22qPmJA/kBdco96i7wA03QHDlE1HRnHEynom6yCh2CLowPfrCLKJi6
|
||||
EeWY23ZFwXxHwb63to10T6jsMUfUD8vjgb3TBwc0IfsJtbXxQ1t8ebHc9eHwwWFCaf0pjI5CnzjnOAbV
|
||||
2SStq5oXq/eDaauEtowmtxyT1fqaBxQ5JVxWpx4na9tREzsURo5qa33rsqSIPaW0mqqR4XJC/ZB5tqQr
|
||||
zb5HY4xf1RIsgj68MC45RWuM743l4Fe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
|
||||
k7abgeyZ0stSNdn2FW9GzzSvONtJGl2wp07I4WbFq2SxkrDt6pMF+/Rqc2UO7xPFFcc8L6hUbffbHF2y
|
||||
XWIaDSkHtvwH3DamK/HTtgtb68JJf8yaVk2MXRDn8NZJb57IJuQ4JUWTDfrt/rGjvl9xY0N1XnDcXEr+
|
||||
ZbUiBI9doMH2l23eIgjfo92dPEdctmn+CsNqicRktxszzgEfeYg4mSMaSuS9mfXO9kHpaMH/AgAA//8f
|
||||
O6UajwkAAA==
|
||||
`,
|
||||
},
|
||||
|
||||
"/": {
|
||||
name: "/",
|
||||
local: `.`,
|
||||
isDir: true,
|
||||
},
|
||||
|
||||
"/codenames": {
|
||||
name: "codenames",
|
||||
local: `codenames`,
|
||||
isDir: true,
|
||||
},
|
||||
}
|
||||
|
||||
var _escDirs = map[string][]os.FileInfo{
|
||||
|
||||
".": {
|
||||
_escData["/codenames"],
|
||||
},
|
||||
|
||||
"codenames": {
|
||||
_escData["/codenames/README.md"],
|
||||
_escData["/codenames/default.txt"],
|
||||
_escData["/codenames/duet.txt"],
|
||||
_escData["/codenames/undercover.txt"],
|
||||
},
|
||||
}
|
|
@ -1,11 +1,22 @@
|
|||
package static
|
||||
|
||||
import "github.com/zikaeroh/codies/internal/words"
|
||||
|
||||
//go:generate go run github.com/mjibson/esc -o=esc.go -pkg=static -ignore=^(static|esc)\.go$ -modtime=0 -private .
|
||||
import (
|
||||
"github.com/zikaeroh/codies/internal/pkger"
|
||||
"github.com/zikaeroh/codies/internal/words"
|
||||
)
|
||||
|
||||
var (
|
||||
Default = words.NewListFromLines(_escFSMustString(false, "/codenames/default.txt"))
|
||||
Duet = words.NewListFromLines(_escFSMustString(false, "/codenames/duet.txt"))
|
||||
Undercover = words.NewListFromLines(_escFSMustString(false, "/codenames/undercover.txt"))
|
||||
Default = load("/default.txt")
|
||||
Duet = load("/duet.txt")
|
||||
Undercover = load("/undercover.txt")
|
||||
)
|
||||
|
||||
func load(filename string) words.List {
|
||||
f, err := pkger.Dir("/internal/words/static/codenames").Open(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return words.NewListFromLines(f)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package static_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/zikaeroh/codies/internal/words"
|
||||
"github.com/zikaeroh/codies/internal/words/static"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func TestLen(t *testing.T) {
|
||||
testLen := func(t *testing.T, name string, list words.List, want int) {
|
||||
t.Helper()
|
||||
assert.Equal(t, list.Len(), want)
|
||||
}
|
||||
|
||||
testLen(t, "Default", static.Default, 400)
|
||||
testLen(t, "Duet", static.Duet, 400)
|
||||
testLen(t, "Undercover", static.Undercover, 390)
|
||||
}
|
|
@ -2,6 +2,7 @@ package words
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -27,17 +28,18 @@ func NewList(words []string) List {
|
|||
return newList(cleaned)
|
||||
}
|
||||
|
||||
func NewListFromLines(s string) List {
|
||||
s = strings.TrimSpace(s)
|
||||
words := make([]string, 0, strings.Count(s, "\n"))
|
||||
scanner := bufio.NewScanner(strings.NewReader(s))
|
||||
func NewListFromLines(r io.Reader) List {
|
||||
var words []string
|
||||
scanner := bufio.NewScanner(r)
|
||||
|
||||
for scanner.Scan() {
|
||||
word := scanner.Text()
|
||||
word = strings.TrimSpace(word)
|
||||
word = strings.ToUpper(word)
|
||||
if word != "" {
|
||||
words = append(words, word)
|
||||
}
|
||||
}
|
||||
|
||||
return newList(words)
|
||||
}
|
||||
|
|
3
main.go
3
main.go
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/posener/ctxutil"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/tomwright/queryparam/v4"
|
||||
"github.com/zikaeroh/codies/internal/pkger"
|
||||
"github.com/zikaeroh/codies/internal/protocol"
|
||||
"github.com/zikaeroh/codies/internal/responder"
|
||||
"github.com/zikaeroh/codies/internal/server"
|
||||
|
@ -230,7 +231,7 @@ func main() {
|
|||
}
|
||||
|
||||
func staticHandler() http.Handler {
|
||||
fs := http.Dir("./frontend/build")
|
||||
fs := pkger.Dir("/frontend/build")
|
||||
fsh := http.FileServer(fs)
|
||||
|
||||
r := chi.NewMux()
|
||||
|
|
Loading…
Reference in New Issue