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:
rm -rf client/dist/
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",
"private": true,
"scripts": {

View File

@ -3,10 +3,11 @@ info:
@perl -ne 'm/^([a-zA-Z0-9\-]+):/ && print(" $$1\n");' Makefile
build:
cd src/ && go build -o ../knowyt knowyt.go
$(MAKE) generate
go build -o knowyt src/knowyt.go
run:
cd src/ && go run knowyt.go
go run src/knowyt.go
run-loop:
pexec -R -c -e TARGET \
@ -22,3 +23,13 @@ _run-endless-loop:
_run-inotify-restart:
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
import (
"sirlab.de/go/knyt/applicationConfig"
"sirlab.de/go/knyt/game"
"sirlab.de/go/knyt/user"
"sirlab.de/go/knowyt/applicationConfig"
"sirlab.de/go/knowyt/game"
"sirlab.de/go/knowyt/user"
"time"
)

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"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) {

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"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) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

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

View File

@ -3,7 +3,7 @@ package application
import (
"fmt"
"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) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,8 +2,8 @@ package handler
import (
"net/http"
"sirlab.de/go/knyt/application"
"sirlab.de/go/knyt/user"
"sirlab.de/go/knowyt/application"
"sirlab.de/go/knowyt/user"
)
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 (
"fmt"
"net/http"
"sirlab.de/go/knyt/user"
"sirlab.de/go/knowyt/user"
)
func (authMux *AuthMux) createCookie() *http.Cookie {
return &http.Cookie{
Name: "knyt-auth",
Name: "knowyt-auth",
Path: "/",
HttpOnly: true,
MaxAge: -1,

View File

@ -3,7 +3,7 @@ package handler
import (
"fmt"
"net/http"
"sirlab.de/go/knyt/user"
"sirlab.de/go/knowyt/user"
"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) {
authCookie, err := r.Cookie("knyt-auth")
authCookie, err := r.Cookie("knowyt-auth")
if err != nil {
fmt.Printf("%v\n", err)
return nil, fmt.Errorf("invalid cookie")

View File

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

View File

@ -4,9 +4,9 @@ import (
"fmt"
"net/http"
"os"
"sirlab.de/go/knyt/application"
"sirlab.de/go/knyt/applicationConfig"
"sirlab.de/go/knyt/handler"
"sirlab.de/go/knowyt/application"
"sirlab.de/go/knowyt/applicationConfig"
"sirlab.de/go/knowyt/handler"
)
func main() {
@ -38,8 +38,7 @@ func main() {
mux.PrivateHandleFunc("/api/removeQuote", app.RemoveQuote)
// default handler
fsHandler := http.FileServer(http.Dir("../../client/dist/"))
mux.PublicHandle("/", fsHandler)
http.HandleFunc("/", handler.FileHandler)
// start listening
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