feat: use resources, renamed knyt -> knowyt

This commit is contained in:
Settel 2022-03-03 08:40:14 +01:00
parent b3b7a61167
commit 1dfbd43e22
54 changed files with 113 additions and 68 deletions

View File

@ -39,4 +39,4 @@ run-standalone:
clean: clean:
rm -rf client/dist/ rm -rf client/dist/
rm -rf client/.nuxt/ rm -rf client/.nuxt/
rm -f server/knowyt $(MAKE) -C server clean

View File

@ -1,5 +1,5 @@
{ {
"name": "knyt", "name": "knowyt",
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"scripts": { "scripts": {

View File

@ -3,10 +3,11 @@ info:
@perl -ne 'm/^([a-zA-Z0-9\-]+):/ && print(" $$1\n");' Makefile @perl -ne 'm/^([a-zA-Z0-9\-]+):/ && print(" $$1\n");' Makefile
build: build:
cd src/ && go build -o ../knowyt knowyt.go $(MAKE) generate
go build -o knowyt src/knowyt.go
run: run:
cd src/ && go run knowyt.go go run src/knowyt.go
run-loop: run-loop:
pexec -R -c -e TARGET \ pexec -R -c -e TARGET \
@ -22,3 +23,13 @@ _run-endless-loop:
_run-inotify-restart: _run-inotify-restart:
inotifyloop --exclude 'data/.*' . curl -s http://localhost:32039/__intern__/exit inotifyloop --exclude 'data/.*' . curl -s http://localhost:32039/__intern__/exit
clean:
rm -f knowyt
rm -f src/resources/*-generated.go
generate: src/resources/dist-generated.go
src/resources/dist-generated.go: $(shell find ../client/dist -type f)
src/resources/dist-generated.go: src/resources/dist-build.go
go generate src/resources/dist-build.go

View File

@ -1,9 +1,9 @@
package application package application
import ( import (
"sirlab.de/go/knyt/applicationConfig" "sirlab.de/go/knowyt/applicationConfig"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
"time" "time"
) )

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) CollectQuotes(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) CollectQuotes(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) ContinueGame(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) ContinueGame(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) DeletePlayer(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) DeletePlayer(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) FinishGame(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) FinishGame(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -1,7 +1,7 @@
package application package application
import ( import (
"sirlab.de/go/knyt/applicationConfig" "sirlab.de/go/knowyt/applicationConfig"
) )
func (app *Application) GetConfig() applicationConfig.ApplicationConfig { func (app *Application) GetConfig() applicationConfig.ApplicationConfig {

View File

@ -2,7 +2,7 @@ package application
import ( import (
"fmt" "fmt"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
) )
func (app Application) GetGameById(id string) (*game.Game, error) { func (app Application) GetGameById(id string) (*game.Game, error) {

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) GetGameInfo(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) GetGameInfo(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) GetQuotes(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) GetQuotes(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -2,7 +2,7 @@ package application
import ( import (
"fmt" "fmt"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app Application) GetUserById(id string) (*user.User, error) { func (app Application) GetUserById(id string) (*user.User, error) {

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
) )
func (app *Application) loadGameState(gm *game.Game, fileName string) error { func (app *Application) loadGameState(gm *game.Game, fileName string) error {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"os" "os"
"path" "path"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
) )
func (app Application) loadGames() error { func (app Application) loadGames() error {

View File

@ -3,8 +3,8 @@ package application
import ( import (
"os" "os"
"path" "path"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
"sirlab.de/go/knyt/quote" "sirlab.de/go/knowyt/quote"
) )
func (app Application) loadQuotes(gm *game.Game, dirName string) error { func (app Application) loadQuotes(gm *game.Game, dirName string) error {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"os" "os"
"path" "path"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app Application) loadUsers() error { func (app Application) loadUsers() error {

View File

@ -1,7 +1,7 @@
package application package application
import ( import (
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
"time" "time"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"path" "path"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) RemoveQuote(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) RemoveQuote(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) ResetGame(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) ResetGame(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"os" "os"
"path" "path"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
) )
func (app *Application) saveGameState(gm *game.Game) error { func (app *Application) saveGameState(gm *game.Game) error {

View File

@ -5,8 +5,8 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"net/http" "net/http"
"path" "path"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) SavePlayer(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) SavePlayer(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -5,8 +5,8 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"net/http" "net/http"
"path" "path"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) SaveQuote(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) SaveQuote(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) SaveSelection(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) SaveSelection(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) SetGameName(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) SetGameName(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) StartGame(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) StartGame(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -1,9 +1,9 @@
package application package application
import ( import (
"sirlab.de/go/knyt/applicationConfig" "sirlab.de/go/knowyt/applicationConfig"
"sirlab.de/go/knyt/game" "sirlab.de/go/knowyt/game"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
"sync" "sync"
"time" "time"
) )

View File

@ -3,7 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (app *Application) SyncHandler(usr *user.User, w http.ResponseWriter, r *http.Request) { func (app *Application) SyncHandler(usr *user.User, w http.ResponseWriter, r *http.Request) {

View File

@ -2,7 +2,7 @@ package engine
import ( import (
"github.com/imkira/go-observer" "github.com/imkira/go-observer"
"sirlab.de/go/knyt/syncdata" "sirlab.de/go/knowyt/syncdata"
"time" "time"
) )

View File

@ -2,7 +2,7 @@ package engine
import ( import (
"fmt" "fmt"
"sirlab.de/go/knyt/syncdata" "sirlab.de/go/knowyt/syncdata"
) )
func (eng *Engine) publish(populateSyncDataCb PopulateSyncDataCb) { func (eng *Engine) publish(populateSyncDataCb PopulateSyncDataCb) {

View File

@ -3,7 +3,7 @@ package engine
import ( import (
"github.com/imkira/go-observer" "github.com/imkira/go-observer"
"net/http" "net/http"
"sirlab.de/go/knyt/syncdata" "sirlab.de/go/knowyt/syncdata"
"sync" "sync"
) )

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/syncdata" "sirlab.de/go/knowyt/syncdata"
"strconv" "strconv"
) )

View File

@ -1,7 +1,7 @@
package game package game
import ( import (
"sirlab.de/go/knyt/quote" "sirlab.de/go/knowyt/quote"
) )
func (gm *Game) AddQuote(qu *quote.Quote) { func (gm *Game) AddQuote(qu *quote.Quote) {

View File

@ -4,8 +4,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"sirlab.de/go/knyt/engine" "sirlab.de/go/knowyt/engine"
"sirlab.de/go/knyt/quote" "sirlab.de/go/knowyt/quote"
) )
func NewGameFromFile(id, fileName string) (*Game, error) { func NewGameFromFile(id, fileName string) (*Game, error) {

View File

@ -2,7 +2,7 @@ package game
import ( import (
"fmt" "fmt"
"sirlab.de/go/knyt/quote" "sirlab.de/go/knowyt/quote"
) )
func (gm *Game) getQuoteById(id string) (*quote.Quote, error) { func (gm *Game) getQuoteById(id string) (*quote.Quote, error) {

View File

@ -1,7 +1,7 @@
package game package game
import ( import (
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (gm *Game) GetQuotesInfoByUser(usr *user.User) *QuotesInfo { func (gm *Game) GetQuotesInfoByUser(usr *user.User) *QuotesInfo {

View File

@ -2,7 +2,7 @@ package game
import ( import (
"fmt" "fmt"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (gm *Game) EventPlayerJoins(usr *user.User) { func (gm *Game) EventPlayerJoins(usr *user.User) {

View File

@ -1,7 +1,7 @@
package game package game
import ( import (
"sirlab.de/go/knyt/syncdata" "sirlab.de/go/knowyt/syncdata"
"sort" "sort"
) )

View File

@ -2,7 +2,7 @@ package game
import ( import (
"fmt" "fmt"
"sirlab.de/go/knyt/syncdata" "sirlab.de/go/knowyt/syncdata"
) )
func (gm *Game) populateGetRoundInfo() *syncdata.RoundInfo { func (gm *Game) populateGetRoundInfo() *syncdata.RoundInfo {

View File

@ -1,7 +1,7 @@
package game package game
import ( import (
"sirlab.de/go/knyt/syncdata" "sirlab.de/go/knowyt/syncdata"
) )
func (gm *Game) populateSyncDataCb(syncData *syncdata.SyncData) { func (gm *Game) populateSyncDataCb(syncData *syncdata.SyncData) {

View File

@ -3,7 +3,7 @@ package game
import ( import (
"fmt" "fmt"
"os" "os"
"sirlab.de/go/knyt/quote" "sirlab.de/go/knowyt/quote"
) )
func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error { func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {

View File

@ -2,7 +2,7 @@ package game
import ( import (
"fmt" "fmt"
"sirlab.de/go/knyt/quote" "sirlab.de/go/knowyt/quote"
) )
func (gm *Game) CreateQuote(fileName, usrId, quoteId, quoteText string) error { func (gm *Game) CreateQuote(fileName, usrId, quoteId, quoteText string) error {

View File

@ -2,7 +2,7 @@ package game
import ( import (
"fmt" "fmt"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (gm *Game) SaveSelection(usr *user.User, selection string) { func (gm *Game) SaveSelection(usr *user.User, selection string) {

View File

@ -3,7 +3,7 @@ package game
import ( import (
"fmt" "fmt"
"math/rand" "math/rand"
"sirlab.de/go/knyt/quote" "sirlab.de/go/knowyt/quote"
"time" "time"
) )

View File

@ -1,8 +1,8 @@
package game package game
import ( import (
"sirlab.de/go/knyt/engine" "sirlab.de/go/knowyt/engine"
"sirlab.de/go/knyt/quote" "sirlab.de/go/knowyt/quote"
"sync" "sync"
) )

View File

@ -1,4 +1,4 @@
module sirlab.de/go/knyt module sirlab.de/go/knowyt
go 1.16 go 1.16

View File

@ -2,8 +2,8 @@ package handler
import ( import (
"net/http" "net/http"
"sirlab.de/go/knyt/application" "sirlab.de/go/knowyt/application"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
type HandlerFunc func(http.ResponseWriter, *http.Request) type HandlerFunc func(http.ResponseWriter, *http.Request)

View File

@ -0,0 +1,31 @@
package handler
import (
"fmt"
"mime"
"net/http"
"path"
"sirlab.de/go/knowyt/resources"
)
func FileHandler(w http.ResponseWriter, req *http.Request) {
uri := req.URL.String()
if uri[len(uri)-1] == '/' {
uri += "index.html"
}
uri = uri[1:]
data, err := Resources.Asset(uri)
if err != nil {
fmt.Printf("%s: %v\n", uri, err)
http.NotFoundHandler().ServeHTTP(w, req)
return
}
mimeType := mime.TypeByExtension(path.Ext(uri))
if mimeType == "" {
mimeType = "text/plain"
}
w.Header().Add("Content-Type", mimeType)
fmt.Fprint(w, string(data))
}

View File

@ -3,12 +3,12 @@ package handler
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
func (authMux *AuthMux) createCookie() *http.Cookie { func (authMux *AuthMux) createCookie() *http.Cookie {
return &http.Cookie{ return &http.Cookie{
Name: "knyt-auth", Name: "knowyt-auth",
Path: "/", Path: "/",
HttpOnly: true, HttpOnly: true,
MaxAge: -1, MaxAge: -1,

View File

@ -3,7 +3,7 @@ package handler
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
"strings" "strings"
) )
@ -25,7 +25,7 @@ func (authMux *AuthMux) accessDenied(w http.ResponseWriter, r *http.Request) {
} }
func (authMux *AuthMux) getUserFromSession(r *http.Request) (*user.User, error) { func (authMux *AuthMux) getUserFromSession(r *http.Request) (*user.User, error) {
authCookie, err := r.Cookie("knyt-auth") authCookie, err := r.Cookie("knowyt-auth")
if err != nil { if err != nil {
fmt.Printf("%v\n", err) fmt.Printf("%v\n", err)
return nil, fmt.Errorf("invalid cookie") return nil, fmt.Errorf("invalid cookie")

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sirlab.de/go/knyt/user" "sirlab.de/go/knowyt/user"
) )
type UserInfoJson struct { type UserInfoJson struct {

View File

@ -4,9 +4,9 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
"sirlab.de/go/knyt/application" "sirlab.de/go/knowyt/application"
"sirlab.de/go/knyt/applicationConfig" "sirlab.de/go/knowyt/applicationConfig"
"sirlab.de/go/knyt/handler" "sirlab.de/go/knowyt/handler"
) )
func main() { func main() {
@ -38,8 +38,7 @@ func main() {
mux.PrivateHandleFunc("/api/removeQuote", app.RemoveQuote) mux.PrivateHandleFunc("/api/removeQuote", app.RemoveQuote)
// default handler // default handler
fsHandler := http.FileServer(http.Dir("../../client/dist/")) http.HandleFunc("/", handler.FileHandler)
mux.PublicHandle("/", fsHandler)
// start listening // start listening
fmt.Printf("http://localhost:%d/\n", mux.Port) fmt.Printf("http://localhost:%d/\n", mux.Port)

1
server/src/resources/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*-generated.go

View File

@ -0,0 +1,3 @@
package Resources
//go:generate go-bindata -pkg Resources -o dist-generated.go --prefix ../../../client/dist/ ../../../client/dist/ ../../../client/dist/_nuxt/ ../../../client/dist/play ../../../client/dist/admin ../../../client/dist/fonts/dosis ../../../client/dist/fonts/wendy-one