Skip to content

Commit

Permalink
Merge pull request #108 from bk2204/embed
Browse files Browse the repository at this point in the history
Switch from using rice to embed for embedding assets
  • Loading branch information
bk2204 authored Sep 21, 2022
2 parents 4b398d2 + 6dd7747 commit 0ef8949
Show file tree
Hide file tree
Showing 68 changed files with 10 additions and 8,224 deletions.
13 changes: 0 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ would like to make that are not dependent upon each other, consider submitting
them as separate pull requests.
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).

## Updating management templates
0. Install go.rice with `go install github.com/GeertJohan/go.rice`
0. Run `rice embed-go` after all template changes have been made
0. Commit the change
0. Submit a pull request.

## Updating 3rd party packages

0. Run `godep save` to add new dependencies.
0. Run `godep update foo/bar` to update the package `foo/bar`.
0. Commit the change. lfs-test-server vendors the full source code in the repository.
0. Submit a pull request.

## Resources

- [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/)
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
module github.com/git-lfs/lfs-test-server

require (
github.com/GeertJohan/go.rice v0.0.0-20150223153050-b4a18af23143
github.com/boltdb/bolt v0.0.0-20150329202000-ee954308d641
github.com/daaku/go.zipexe v0.0.0-20150329023125-a5fe2436ffcb // indirect
github.com/gorilla/context v0.0.0-20141217160251-215affda49ad
github.com/gorilla/mux v0.0.0-20140926153814-e444e69cbd2e
github.com/kardianos/osext v0.0.0-20150317202929-efacde031546 // indirect
)

go 1.11
go 1.16
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
github.com/GeertJohan/go.rice v0.0.0-20150223153050-b4a18af23143 h1:0L4z7oi0t4/RLLqJ1aCiGGcxvJBGIUBlzxaOasPI3Xg=
github.com/GeertJohan/go.rice v0.0.0-20150223153050-b4a18af23143/go.mod h1:DgrzXonpdQbfN3uYaGz1EG4Sbhyum/MMIn6Cphlh2bw=
github.com/boltdb/bolt v0.0.0-20150329202000-ee954308d641 h1:HzvhaGdNSavlePHbf8gWLk+4PScN+/BP3n+M7CYi6Jg=
github.com/boltdb/bolt v0.0.0-20150329202000-ee954308d641/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/daaku/go.zipexe v0.0.0-20150329023125-a5fe2436ffcb h1:tUf55Po0vzOendQ7NWytcdK0VuzQmfAgvGBUOQvN0WA=
github.com/daaku/go.zipexe v0.0.0-20150329023125-a5fe2436ffcb/go.mod h1:U0vRfAucUOohvdCxt5MWLF+TePIL0xbCkbKIiV8TQCE=
github.com/gorilla/context v0.0.0-20141217160251-215affda49ad h1:wJwKN6X6iRRVnjdBgrkWjhBOvYm7yw5boqXwFUnBtbE=
github.com/gorilla/context v0.0.0-20141217160251-215affda49ad/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v0.0.0-20140926153814-e444e69cbd2e h1:nH09qCdJVZxw0nRVfm14xjXkw2puLyLPN56n4u+vTC0=
github.com/gorilla/mux v0.0.0-20140926153814-e444e69cbd2e/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/kardianos/osext v0.0.0-20150317202929-efacde031546 h1:ePuu22vwJOsd649X5+JBojWixIwf52QeREpSsykv7Q8=
github.com/kardianos/osext v0.0.0-20150317202929-efacde031546/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"crypto/tls"
"embed"
"fmt"
"net"
"os"
Expand All @@ -20,6 +21,9 @@ var (
logger = NewKVLogger(os.Stdout)
)

//go:embed all:mgmt
var embedded embed.FS

// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
// connections. It's used by ListenAndServe and ListenAndServeTLS so
// dead TCP connections (e.g. closing laptop mid-download) eventually
Expand Down
42 changes: 0 additions & 42 deletions mgmt-css.rice-box.go

This file was deleted.

70 changes: 0 additions & 70 deletions mgmt-templates.rice-box.go

This file was deleted.

16 changes: 5 additions & 11 deletions mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ import (
"io"
"net/http"

"github.com/GeertJohan/go.rice"
"github.com/gorilla/mux"
)

var (
cssBox *rice.Box
templateBox *rice.Box
)

type pageData struct {
Name string
Config *Configuration
Expand All @@ -33,14 +27,12 @@ func (a *App) addMgmt(r *mux.Router) {
r.HandleFunc("/mgmt/add", basicAuth(a.addUserHandler)).Methods("POST")
r.HandleFunc("/mgmt/del", basicAuth(a.delUserHandler)).Methods("POST")

cssBox = rice.MustFindBox("mgmt/css")
templateBox = rice.MustFindBox("mgmt/templates")
r.HandleFunc("/mgmt/css/{file}", basicAuth(cssHandler))
}

func cssHandler(w http.ResponseWriter, r *http.Request) {
file := mux.Vars(r)["file"]
f, err := cssBox.Open(file)
f, err := embedded.Open(fmt.Sprintf("mgmt/css/%s", file))
if err != nil {
writeStatus(w, r, 404)
return
Expand Down Expand Up @@ -182,15 +174,17 @@ func (a *App) delUserHandler(w http.ResponseWriter, r *http.Request) {
}

func render(w http.ResponseWriter, tmpl string, data pageData) error {
bodyString, err := templateBox.String("body.tmpl")
body, err := embedded.ReadFile("mgmt/templates/body.tmpl")
if err != nil {
return err
}
bodyString := string(body)

contentString, err := templateBox.String(tmpl)
content, err := embedded.ReadFile(fmt.Sprintf("mgmt/templates/%s", tmpl))
if err != nil {
return err
}
contentString := string(content)

t := template.Must(template.New("main").Parse(bodyString))
t.New("content").Parse(contentString)
Expand Down
7 changes: 0 additions & 7 deletions vendor/github.com/GeertJohan/go.rice/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions vendor/github.com/GeertJohan/go.rice/AUTHORS

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/github.com/GeertJohan/go.rice/LICENSE

This file was deleted.

152 changes: 0 additions & 152 deletions vendor/github.com/GeertJohan/go.rice/README.md

This file was deleted.

Loading

0 comments on commit 0ef8949

Please sign in to comment.