mirror of https://github.com/dirtbags/moth.git
go fmt
This commit is contained in:
parent
dc4fa96f9e
commit
628d8a0b05
|
@ -14,17 +14,17 @@ import (
|
||||||
|
|
||||||
// https://github.com/omniti-labs/jsend
|
// https://github.com/omniti-labs/jsend
|
||||||
type JSend struct {
|
type JSend struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Data struct {
|
Data struct {
|
||||||
Short string `json:"short"`
|
Short string `json:"short"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
JSendSuccess = "success"
|
JSendSuccess = "success"
|
||||||
JSendFail = "fail"
|
JSendFail = "fail"
|
||||||
JSendError = "error"
|
JSendError = "error"
|
||||||
)
|
)
|
||||||
|
|
||||||
func respond(w http.ResponseWriter, req *http.Request, status string, short string, format string, a ...interface{}) {
|
func respond(w http.ResponseWriter, req *http.Request, status string, short string, format string, a ...interface{}) {
|
||||||
|
@ -255,7 +255,7 @@ func (ctx *Instance) staticHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type FurtiveResponseWriter struct {
|
type FurtiveResponseWriter struct {
|
||||||
w http.ResponseWriter
|
w http.ResponseWriter
|
||||||
statusCode *int
|
statusCode *int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ func (w FurtiveResponseWriter) Header() http.Header {
|
||||||
// This gives Instances the signature of http.Handler
|
// This gives Instances the signature of http.Handler
|
||||||
func (ctx *Instance) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
|
func (ctx *Instance) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
|
||||||
w := FurtiveResponseWriter{
|
w := FurtiveResponseWriter{
|
||||||
w: wOrig,
|
w: wOrig,
|
||||||
statusCode: new(int),
|
statusCode: new(int),
|
||||||
}
|
}
|
||||||
ctx.mux.ServeHTTP(w, r)
|
ctx.mux.ServeHTTP(w, r)
|
||||||
|
@ -297,4 +297,3 @@ func (ctx *Instance) BindHandlers() {
|
||||||
ctx.mux.HandleFunc(ctx.Base+"/puzzles.json", ctx.puzzlesHandler)
|
ctx.mux.HandleFunc(ctx.Base+"/puzzles.json", ctx.puzzlesHandler)
|
||||||
ctx.mux.HandleFunc(ctx.Base+"/points.json", ctx.pointsHandler)
|
ctx.mux.HandleFunc(ctx.Base+"/points.json", ctx.pointsHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,12 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"math/rand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
|
@ -23,7 +23,7 @@ type Instance struct {
|
||||||
update chan bool
|
update chan bool
|
||||||
jPuzzleList []byte
|
jPuzzleList []byte
|
||||||
jPointsLog []byte
|
jPointsLog []byte
|
||||||
mux *http.ServeMux
|
mux *http.ServeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInstance(base, mothballDir, stateDir, resourcesDir string) (*Instance, error) {
|
func NewInstance(base, mothballDir, stateDir, resourcesDir string) (*Instance, error) {
|
||||||
|
@ -44,7 +44,7 @@ func NewInstance(base, mothballDir, stateDir, resourcesDir string) (*Instance, e
|
||||||
if _, err := os.Stat(stateDir); err != nil {
|
if _, err := os.Stat(stateDir); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.BindHandlers()
|
ctx.BindHandlers()
|
||||||
ctx.MaybeInitialize()
|
ctx.MaybeInitialize()
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ const distinguishableChars = "234678abcdefhijkmnpqrtwxyz="
|
||||||
|
|
||||||
func mktoken() string {
|
func mktoken() string {
|
||||||
a := make([]byte, 8)
|
a := make([]byte, 8)
|
||||||
for i := range(a) {
|
for i := range a {
|
||||||
char := rand.Intn(len(distinguishableChars))
|
char := rand.Intn(len(distinguishableChars))
|
||||||
a[i] = distinguishableChars[char]
|
a[i] = distinguishableChars[char]
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,17 @@ package main
|
||||||
import (
|
import (
|
||||||
"github.com/namsral/flag"
|
"github.com/namsral/flag"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
"math/rand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func setup() error {
|
func setup() error {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
base := flag.String(
|
base := flag.String(
|
||||||
"base",
|
"base",
|
||||||
|
|
Loading…
Reference in New Issue