Skip to content

Commit c44c690

Browse files
committed
Switch chromad to go:embed and show version.
1 parent 7410d4a commit c44c690

File tree

6 files changed

+30
-20
lines changed

6 files changed

+30
-20
lines changed

Diff for: .circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
environment:
1616
GO111MODULE: "on"
1717
docker:
18-
- image: circleci/golang:1.15
18+
- image: circleci/golang:1.16
1919
working_directory: /go/src/github.com/alecthomas/chroma
2020
steps:
2121
- checkout
@@ -36,7 +36,7 @@ jobs:
3636
./bin/golangci-lint run
3737
release:
3838
docker:
39-
- image: circleci/golang:1.15
39+
- image: circleci/golang:1.16
4040
steps:
4141
- checkout
4242
- run: curl -sL https://git.io/goreleaser | bash

Diff for: Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.PHONY: chromad upload all
22

3+
VERSION ?= $(shell git describe --tags --dirty --always)
4+
35
all: README.md tokentype_string.go
46

57
README.md: lexers/*/*.go
@@ -9,10 +11,8 @@ tokentype_string.go: types.go
911
go generate
1012

1113
chromad:
12-
(cd ./cmd/chromad && go get github.com/GeertJohan/go.rice/rice@master && go install github.com/GeertJohan/go.rice/rice)
1314
rm -f chromad
14-
(export CGOENABLED=0 GOOS=linux ; cd ./cmd/chromad && go build -o ../../chromad .)
15-
rice append -i ./cmd/chromad --exec=./chromad
15+
(export CGOENABLED=0 GOOS=linux ; cd ./cmd/chromad && go build -ldflags="-X 'main.version=$(VERSION)'" -o ../../chromad .)
1616

1717
upload: chromad
1818
scp chromad [email protected]: && \

Diff for: cmd/chromad/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/alecthomas/chroma/cmd/chromad
22

3-
go 1.13
3+
go 1.16
44

55
require (
66
github.com/GeertJohan/go.rice v1.0.2

Diff for: cmd/chromad/go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg=
12
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
23
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
34
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
5+
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
46
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
57
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=
68
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
@@ -32,11 +34,13 @@ github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyC
3234
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
3335
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
3436
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
37+
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
3538
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
3639
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
3740
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
3841
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
3942
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
43+
github.com/nkovacs/streamquote v1.0.0 h1:PmVIV08Zlx2lZK5fFZlMZ04eHcDTIFJCv/5/0twVUow=
4044
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
4145
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
4246
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -50,7 +54,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
5054
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
5155
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
5256
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
57+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
5358
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
59+
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
5460
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
5561
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5662
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

Diff for: cmd/chromad/main.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package main
22

33
import (
4+
"embed"
45
"encoding/json"
5-
"fmt"
66
"html/template"
77
"log"
88
"net/http"
99
"sort"
1010
"strings"
1111

12-
rice "github.com/GeertJohan/go.rice"
1312
"github.com/alecthomas/kong"
1413
konghcl "github.com/alecthomas/kong-hcl"
1514
"github.com/gorilla/csrf"
@@ -23,10 +22,14 @@ import (
2322
)
2423

2524
var (
26-
templateFiles = rice.MustFindBox("templates")
27-
staticFiles = rice.MustFindBox("static")
25+
version = "devel"
2826

29-
htmlTemplate = template.Must(template.New("html").Parse(templateFiles.MustString("index.html.tmpl")))
27+
//go:embed templates/index.html.tmpl
28+
indexTemplate string
29+
//go:embed static
30+
staticFiles embed.FS
31+
32+
htmlTemplate = template.Must(template.New("html").Parse(indexTemplate))
3033
)
3134

3235
type context struct {
@@ -124,7 +127,7 @@ func newContext(r *http.Request) context {
124127
ctx := context{
125128
SelectedStyle: "monokailight",
126129
CSRFField: csrf.TemplateField(r),
127-
Version: fmt.Sprintf("%d", staticFiles.Time().Unix()),
130+
Version: version,
128131
}
129132
style := styles.Get(ctx.SelectedStyle)
130133
if style == nil {
@@ -147,18 +150,19 @@ func newContext(r *http.Request) context {
147150

148151
func main() {
149152
var cli struct {
150-
Config kong.ConfigFlag `help:"Load configuration." placeholder:"FILE"`
151-
Bind string `help:"HTTP bind address." default:"127.0.0.1:8080"`
152-
CSRFKey string `help:"CSRF key." default:""`
153+
Version kong.VersionFlag `help:"Show version."`
154+
Config kong.ConfigFlag `help:"Load configuration." placeholder:"FILE"`
155+
Bind string `help:"HTTP bind address." default:"127.0.0.1:8080"`
156+
CSRFKey string `help:"CSRF key." default:""`
153157
}
154-
ctx := kong.Parse(&cli, kong.Configuration(konghcl.Loader))
158+
ctx := kong.Parse(&cli, kong.Configuration(konghcl.Loader), kong.Vars{"version": version})
155159

156-
log.Printf("Starting on http://%s\n", cli.Bind)
160+
log.Printf("Starting chromad %s on http://%s\n", version, cli.Bind)
157161

158162
router := mux.NewRouter()
159163
router.Handle("/", http.HandlerFunc(index)).Methods("GET")
160164
router.Handle("/api/render", http.HandlerFunc(renderHandler)).Methods("POST")
161-
router.Handle("/static/{file:.*}", http.StripPrefix("/static/", http.FileServer(staticFiles.HTTPBox()))).Methods("GET")
165+
router.Handle("/static/{file:.*}", http.FileServer(http.FS(staticFiles))).Methods("GET")
162166

163167
options := []csrf.Option{}
164168
if cli.CSRFKey == "" {

Diff for: cmd/chromad/templates/index.html.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22
<html>
33
<head>
4-
<title>Chroma Playground</title>
4+
<title>Chroma Playground ({{.Version}})</title>
55
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css"/>
66
<style>
77
textarea {
@@ -21,7 +21,7 @@
2121
<body>
2222
<div class="container">
2323

24-
<h1 class="title">Chroma Playground</h1>
24+
<h1 class="title">Chroma Playground ({{.Version}})</h1>
2525

2626
<div class="notification">
2727
<a href="https://github.com/alecthomas/chroma">Chroma</a> is a general purpose syntax highlighter in pure Go.

0 commit comments

Comments
 (0)