Add symbol definitions, code cleanup
This commit is contained in:
34
Makefile
34
Makefile
@@ -1,13 +1,31 @@
|
||||
# Variables
|
||||
BINARY := bin/main
|
||||
SOURCES := $(wildcard src/*.go)
|
||||
|
||||
# Build for the current platform
|
||||
build:
|
||||
go build -o bin/main src/*.go
|
||||
go build -o $(BINARY) $(SOURCES)
|
||||
|
||||
build-linux:
|
||||
GOOS=linux go build -o bin/main src/*.go
|
||||
# Build for Linux
|
||||
build-linux: GOOS := linux
|
||||
build-linux: EXTENSION :=
|
||||
build-linux: build-cross
|
||||
|
||||
build-windows:
|
||||
GOOS=linux go build -p bin/main src/*.go
|
||||
# Build for Windows
|
||||
build-windows: GOOS := windows
|
||||
build-windows: EXTENSION := .exe
|
||||
build-windows: build-cross
|
||||
|
||||
run:
|
||||
go run src/*.go
|
||||
# Cross-compile for a specific platform (used by build-linux and build-windows)
|
||||
build-cross: export GOOS := $(GOOS)
|
||||
build-cross: BINARY := $(BINARY)$(EXTENSION)
|
||||
build-cross: $(BINARY)
|
||||
|
||||
all: build
|
||||
# Run the application
|
||||
run: build
|
||||
./$(BINARY)
|
||||
|
||||
# Clean up generated files
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(BINARY) $(BINARY).exe
|
||||
29
go.mod
29
go.mod
@@ -4,26 +4,31 @@ go 1.17
|
||||
|
||||
require (
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/gofiber/fiber/v2 v2.40.1
|
||||
github.com/joho/godotenv v1.4.0
|
||||
github.com/gofiber/fiber/v2 v2.44.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/mineatar-io/skin-render v1.0.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/klauspost/compress v1.15.9 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/klauspost/compress v1.16.5 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/mattn/go-isatty v0.0.18 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/philhofer/fwd v1.1.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
||||
github.com/tinylib/msgp v1.1.8 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.41.0 // indirect
|
||||
github.com/valyala/fasthttp v1.45.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 // indirect
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
golang.org/x/image v0.7.0 // indirect
|
||||
golang.org/x/sys v0.7.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
)
|
||||
|
||||
103
go.sum
103
go.sum
@@ -1,10 +1,12 @@
|
||||
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
|
||||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
@@ -15,8 +17,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/gofiber/fiber/v2 v2.40.1 h1:pc7n9VVpGIqNsvg9IPLQhyFEMJL8gCs1kneH5D1pIl4=
|
||||
github.com/gofiber/fiber/v2 v2.40.1/go.mod h1:Gko04sLksnHbzLSRBFWPFdzM9Ws9pRxvvIaohJK1dsk=
|
||||
github.com/gofiber/fiber/v2 v2.44.0 h1:Z90bEvPcJM5GFJnu1py0E1ojoerkyew3iiNJ78MQCM8=
|
||||
github.com/gofiber/fiber/v2 v2.44.0/go.mod h1:VTMtb/au8g01iqvHyaCzftuM/xmZgKOZCtFzz6CdV9w=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
@@ -31,21 +33,27 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
|
||||
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
|
||||
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
|
||||
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mineatar-io/skin-render v1.0.1 h1:ukZCagxGuaZM+E16h7XY+xGI+xlnI5R0EfEW0y+BIxs=
|
||||
@@ -64,38 +72,63 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
||||
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
|
||||
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4=
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3D/WJsDd1iXHT96alCoN2KJo6/4x1DZC3wZs8=
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
|
||||
github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0=
|
||||
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.41.0 h1:zeR0Z1my1wDHTRiamBCXVglQdbUwgb9uWG3k1HQz6jY=
|
||||
github.com/valyala/fasthttp v1.41.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY=
|
||||
github.com/valyala/fasthttp v1.45.0 h1:zPkkzpIn8tdHZUrVa6PzYd0i5verqiPSkgTd3bSUcpA=
|
||||
github.com/valyala/fasthttp v1.45.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/image v0.0.0-20220302094943-723b81ca9867/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 h1:/eM0PCrQI2xd471rI+snWuu251/+/jpBpZqir2mPdnU=
|
||||
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
|
||||
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
|
||||
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c h1:yKufUcDwucU5urd+50/Opbt4AYpqthk7wHpHok8f1lo=
|
||||
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -110,19 +143,35 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -136,8 +185,8 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
|
||||
132
src/config.go
132
src/config.go
@@ -7,6 +7,110 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultConfig is the default configuration values used by the application.
|
||||
DefaultConfig *Config = &Config{
|
||||
Host: "127.0.0.1",
|
||||
Port: 3001,
|
||||
Redis: RedisConfig{
|
||||
Host: "127.0.0.1",
|
||||
Port: 6379,
|
||||
User: "",
|
||||
Password: "",
|
||||
Database: 0,
|
||||
},
|
||||
Routes: RoutesConfig{
|
||||
Face: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
Head: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
FullBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
FrontBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
BackBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
LeftBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
RightBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
RawSkin: RouteConfig{
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
},
|
||||
},
|
||||
Cache: CacheConfig{
|
||||
UUIDCacheDuration: time.Hour * 168,
|
||||
SkinCacheDuration: time.Hour * 12,
|
||||
RenderCacheDuration: time.Hour * 12,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// Config is the root configuration object for the application.
|
||||
type Config struct {
|
||||
Host string `yaml:"host"`
|
||||
Port uint16 `yaml:"port"`
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
Routes RoutesConfig `yaml:"routes"`
|
||||
Cache CacheConfig `yaml:"cache"`
|
||||
}
|
||||
|
||||
// RoutesConfig is the configuration data of all API routes.
|
||||
type RoutesConfig struct {
|
||||
Face RouteConfig `yaml:"face"`
|
||||
Head RouteConfig `yaml:"head"`
|
||||
FullBody RouteConfig `yaml:"full_body"`
|
||||
FrontBody RouteConfig `yaml:"front_body"`
|
||||
BackBody RouteConfig `yaml:"back_body"`
|
||||
LeftBody RouteConfig `yaml:"left_body"`
|
||||
RightBody RouteConfig `yaml:"right_body"`
|
||||
RawSkin RouteConfig `yaml:"raw_skin"`
|
||||
}
|
||||
|
||||
// RouteConfig is the configuration data used by a single API route.
|
||||
type RouteConfig struct {
|
||||
DefaultScale int `yaml:"default_scale"`
|
||||
DefaultOverlay bool `yaml:"default_overlay"`
|
||||
@@ -16,6 +120,7 @@ type RouteConfig struct {
|
||||
MaxScale int `yaml:"max_scale"`
|
||||
}
|
||||
|
||||
// RedisConfig is the configuration data used to connect to Redis.
|
||||
type RedisConfig struct {
|
||||
Host string `yaml:"host"`
|
||||
Port uint16 `yaml:"port"`
|
||||
@@ -24,28 +129,15 @@ type RedisConfig struct {
|
||||
Database int `yaml:"database"`
|
||||
}
|
||||
|
||||
type Configuration struct {
|
||||
Host string `yaml:"host"`
|
||||
Port uint16 `yaml:"port"`
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
Routes struct {
|
||||
Face RouteConfig `yaml:"face"`
|
||||
Head RouteConfig `yaml:"head"`
|
||||
FullBody RouteConfig `yaml:"full_body"`
|
||||
FrontBody RouteConfig `yaml:"front_body"`
|
||||
BackBody RouteConfig `yaml:"back_body"`
|
||||
LeftBody RouteConfig `yaml:"left_body"`
|
||||
RightBody RouteConfig `yaml:"right_body"`
|
||||
RawSkin RouteConfig `yaml:"raw_skin"`
|
||||
} `yaml:"routes"`
|
||||
Cache struct {
|
||||
UUIDCacheDuration time.Duration `yaml:"uuid_cache_duration"`
|
||||
SkinCacheDuration time.Duration `yaml:"skin_cache_duration"`
|
||||
RenderCacheDuration time.Duration `yaml:"render_cache_duration"`
|
||||
} `yaml:"cache"`
|
||||
// CacheConfig is the configuration data used to set TTL values for Redis keys.
|
||||
type CacheConfig struct {
|
||||
UUIDCacheDuration time.Duration `yaml:"uuid_cache_duration"`
|
||||
SkinCacheDuration time.Duration `yaml:"skin_cache_duration"`
|
||||
RenderCacheDuration time.Duration `yaml:"render_cache_duration"`
|
||||
}
|
||||
|
||||
func (c *Configuration) ReadFile(file string) error {
|
||||
// ReadFile reads the configuration from the file and parses it as YAML.
|
||||
func (c *Config) ReadFile(file string) error {
|
||||
data, err := os.ReadFile(file)
|
||||
|
||||
if err != nil {
|
||||
|
||||
12
src/main.go
12
src/main.go
@@ -20,8 +20,8 @@ var (
|
||||
return ctx.SendStatus(http.StatusInternalServerError)
|
||||
},
|
||||
})
|
||||
r *Redis = &Redis{}
|
||||
config *Configuration = &Configuration{}
|
||||
r *Redis = &Redis{}
|
||||
conf *Config = &Config{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -29,11 +29,11 @@ func init() {
|
||||
|
||||
godotenv.Load()
|
||||
|
||||
if err = config.ReadFile("config.yml"); err != nil {
|
||||
if err = conf.ReadFile("config.yml"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err = r.Connect(config.Redis); err != nil {
|
||||
if err = r.Connect(conf.Redis); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -56,6 +56,6 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Printf("Listening on %s:%d\n", config.Host, config.Port+instanceID)
|
||||
log.Fatal(app.Listen(fmt.Sprintf("%s:%d", config.Host, config.Port+instanceID)))
|
||||
log.Printf("Listening on %s:%d\n", conf.Host, conf.Port+instanceID)
|
||||
log.Fatal(app.Listen(fmt.Sprintf("%s:%d", conf.Host, conf.Port+instanceID)))
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// MinecraftProfile is Minecraft profile information returned from the Mojang API.
|
||||
type MinecraftProfile struct {
|
||||
Username string `json:"name"`
|
||||
UUID string `json:"id"`
|
||||
}
|
||||
|
||||
// MinecraftProfileTextures is texture information about a Minecraft profile returned from the Mojang API.
|
||||
type MinecraftProfileTextures struct {
|
||||
UUID string `json:"id"`
|
||||
Username string `json:"name"`
|
||||
@@ -24,6 +26,7 @@ type MinecraftProfileTextures struct {
|
||||
} `json:"properties"`
|
||||
}
|
||||
|
||||
// MinecraftDecodedTextures is the decoded object of the Base64-encoded values property in a MinecraftProfileTextures texture value.
|
||||
type MinecraftDecodedTextures struct {
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
UUID string `json:"uuid"`
|
||||
@@ -42,6 +45,7 @@ type MinecraftDecodedTextures struct {
|
||||
} `json:"textures"`
|
||||
}
|
||||
|
||||
// UsernameToUUID converts a Minecraft username into a UUID using Mojang.
|
||||
func UsernameToUUID(username string) (*MinecraftProfile, error) {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.mojang.com/users/profiles/minecraft/%s", username), nil)
|
||||
|
||||
@@ -62,7 +66,7 @@ func UsernameToUUID(username string) (*MinecraftProfile, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("yggdrasil: unexpected response: %s", resp.Status)
|
||||
return nil, fmt.Errorf("mojang: unexpected response: %s", resp.Status)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
@@ -82,6 +86,7 @@ func UsernameToUUID(username string) (*MinecraftProfile, error) {
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// GetProfileTextures returns the textures of a Minecraft player from Mojang.
|
||||
func GetProfileTextures(uuid string) (*MinecraftProfileTextures, error) {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://sessionserver.mojang.com/session/minecraft/profile/%s", uuid), nil)
|
||||
|
||||
@@ -97,12 +102,12 @@ func GetProfileTextures(uuid string) (*MinecraftProfileTextures, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
if resp.StatusCode == 204 {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
if resp.StatusCode == http.StatusNoContent {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("yggdrasil: unexpected response: %s", resp.Status)
|
||||
return nil, fmt.Errorf("mojang: unexpected response: %s", resp.Status)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
@@ -122,6 +127,7 @@ func GetProfileTextures(uuid string) (*MinecraftProfileTextures, error) {
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// GetDecodedTexturesValue decodes the values from a MinecraftProfileTextures texture value.
|
||||
func GetDecodedTexturesValue(value string) (*MinecraftDecodedTextures, error) {
|
||||
rawResult, err := base64.StdEncoding.DecodeString(value)
|
||||
|
||||
@@ -129,11 +135,11 @@ func GetDecodedTexturesValue(value string) (*MinecraftDecodedTextures, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &MinecraftDecodedTextures{}
|
||||
result := MinecraftDecodedTextures{}
|
||||
|
||||
if err = json.Unmarshal(rawResult, result); err != nil {
|
||||
if err = json.Unmarshal(rawResult, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return &result, nil
|
||||
}
|
||||
@@ -11,10 +11,12 @@ import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
// Redis is a utility client for reading and writing values to the Redis server.
|
||||
type Redis struct {
|
||||
conn *redis.Client
|
||||
}
|
||||
|
||||
// Connect connects to the Redis server using the configuration values provided.
|
||||
func (r *Redis) Connect(conf RedisConfig) error {
|
||||
c := redis.NewClient(&redis.Options{
|
||||
Addr: fmt.Sprintf("%s:%d", conf.Host, conf.Port),
|
||||
@@ -32,6 +34,7 @@ func (r *Redis) Connect(conf RedisConfig) error {
|
||||
return c.Ping(ctx).Err()
|
||||
}
|
||||
|
||||
// GetString gets the value from Redis by the key and returns the value as a string.
|
||||
func (r *Redis) GetString(key string) (string, bool, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
|
||||
@@ -52,6 +55,7 @@ func (r *Redis) GetString(key string) (string, bool, error) {
|
||||
return result.Val(), true, result.Err()
|
||||
}
|
||||
|
||||
// GetBytes gets the value from Redis by the key and returns the value as a byte array.
|
||||
func (r *Redis) GetBytes(key string) ([]byte, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
|
||||
@@ -78,6 +82,7 @@ func (r *Redis) GetBytes(key string) ([]byte, error) {
|
||||
return data, err
|
||||
}
|
||||
|
||||
// GetNRGBA gets the value from Redis by the key and returns the value as Go image.NRGBA image type.
|
||||
func (r *Redis) GetNRGBA(key string) (*image.NRGBA, bool, error) {
|
||||
value, err := r.GetBytes(key)
|
||||
|
||||
@@ -106,6 +111,7 @@ func (r *Redis) GetNRGBA(key string) (*image.NRGBA, bool, error) {
|
||||
return img.(*image.NRGBA), true, nil
|
||||
}
|
||||
|
||||
// Exists returns whether or not the key exists in the database.
|
||||
func (r *Redis) Exists(key string) (bool, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
|
||||
@@ -116,6 +122,7 @@ func (r *Redis) Exists(key string) (bool, error) {
|
||||
return result.Val() == 1, result.Err()
|
||||
}
|
||||
|
||||
// Delete deletes the key from the database if it exists.
|
||||
func (r *Redis) Delete(key string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
|
||||
@@ -124,6 +131,7 @@ func (r *Redis) Delete(key string) error {
|
||||
return r.conn.Del(ctx, key).Err()
|
||||
}
|
||||
|
||||
// Set puts the key-value into the database with an optional TTL value.
|
||||
func (r *Redis) Set(key string, value interface{}, ttl time.Duration) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
|
||||
@@ -132,6 +140,7 @@ func (r *Redis) Set(key string, value interface{}, ttl time.Duration) error {
|
||||
return r.conn.Set(ctx, key, value, ttl).Err()
|
||||
}
|
||||
|
||||
// Close closes the connection to the database.
|
||||
func (r *Redis) Close() error {
|
||||
return r.conn.Close()
|
||||
}
|
||||
|
||||
@@ -23,12 +23,14 @@ func init() {
|
||||
app.Use(NotFoundHandler)
|
||||
}
|
||||
|
||||
// PingHandler is the API handler used for the `/ping` route.
|
||||
func PingHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.SendStatus(http.StatusOK)
|
||||
}
|
||||
|
||||
// FullBodyHandler is the API handler used for the `/body/full/:user` route.
|
||||
func FullBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, config.Routes.FullBody)
|
||||
opts := ParseQueryParams(ctx, conf.Routes.FullBody)
|
||||
|
||||
uuid, ok, err := LookupUUID(ParseUserParam(ctx))
|
||||
|
||||
@@ -65,7 +67,7 @@ func FullBodyHandler(ctx *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil {
|
||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -77,8 +79,9 @@ func FullBodyHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.Type("png").Send(data)
|
||||
}
|
||||
|
||||
// FrontBodyHandler is the API handler used for the `/body/front/:user` route.
|
||||
func FrontBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, config.Routes.FrontBody)
|
||||
opts := ParseQueryParams(ctx, conf.Routes.FrontBody)
|
||||
|
||||
uuid, ok, err := LookupUUID(ParseUserParam(ctx))
|
||||
|
||||
@@ -117,7 +120,7 @@ func FrontBodyHandler(ctx *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil {
|
||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -129,8 +132,9 @@ func FrontBodyHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.Type("png").Send(data)
|
||||
}
|
||||
|
||||
// BackBodyHandler is the API handler used for the `/body/back/:user` route.
|
||||
func BackBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, config.Routes.BackBody)
|
||||
opts := ParseQueryParams(ctx, conf.Routes.BackBody)
|
||||
|
||||
uuid, ok, err := LookupUUID(ParseUserParam(ctx))
|
||||
|
||||
@@ -169,7 +173,7 @@ func BackBodyHandler(ctx *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil {
|
||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -181,8 +185,9 @@ func BackBodyHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.Type("png").Send(data)
|
||||
}
|
||||
|
||||
// LeftBodyHandler is the API handler used for the `/body/left/:user` route.
|
||||
func LeftBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, config.Routes.LeftBody)
|
||||
opts := ParseQueryParams(ctx, conf.Routes.LeftBody)
|
||||
|
||||
uuid, ok, err := LookupUUID(ParseUserParam(ctx))
|
||||
|
||||
@@ -221,7 +226,7 @@ func LeftBodyHandler(ctx *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil {
|
||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -233,8 +238,9 @@ func LeftBodyHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.Type("png").Send(data)
|
||||
}
|
||||
|
||||
// RightBodyHandler is the API handler used for the `/body/right/:user` route.
|
||||
func RightBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, config.Routes.RightBody)
|
||||
opts := ParseQueryParams(ctx, conf.Routes.RightBody)
|
||||
|
||||
uuid, ok, err := LookupUUID(ParseUserParam(ctx))
|
||||
|
||||
@@ -273,7 +279,7 @@ func RightBodyHandler(ctx *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil {
|
||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -285,8 +291,9 @@ func RightBodyHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.Type("png").Send(data)
|
||||
}
|
||||
|
||||
// FaceHandler is the API handler used for the `/face/:user` route.
|
||||
func FaceHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, config.Routes.Face)
|
||||
opts := ParseQueryParams(ctx, conf.Routes.Face)
|
||||
|
||||
uuid, ok, err := LookupUUID(ParseUserParam(ctx))
|
||||
|
||||
@@ -325,7 +332,7 @@ func FaceHandler(ctx *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil {
|
||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -337,8 +344,9 @@ func FaceHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.Type("png").Send(data)
|
||||
}
|
||||
|
||||
// HeadHandler is the API handler used for the `/head/:user` route.
|
||||
func HeadHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, config.Routes.Head)
|
||||
opts := ParseQueryParams(ctx, conf.Routes.Head)
|
||||
|
||||
uuid, ok, err := LookupUUID(ParseUserParam(ctx))
|
||||
|
||||
@@ -377,7 +385,7 @@ func HeadHandler(ctx *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil {
|
||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -389,8 +397,9 @@ func HeadHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.Type("png").Send(data)
|
||||
}
|
||||
|
||||
// SkinHandler is the API handler used for the `/skin/:user` route.
|
||||
func SkinHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, config.Routes.RawSkin)
|
||||
opts := ParseQueryParams(ctx, conf.Routes.RawSkin)
|
||||
|
||||
uuid, ok, err := LookupUUID(ParseUserParam(ctx))
|
||||
|
||||
@@ -421,6 +430,7 @@ func SkinHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.Type("png").Send(data)
|
||||
}
|
||||
|
||||
// UUIDHandler is the API handler used for the `/uuid/:user` route.
|
||||
func UUIDHandler(ctx *fiber.Ctx) error {
|
||||
uuid, ok, err := LookupUUID(ctx.Params("user"))
|
||||
|
||||
@@ -435,6 +445,7 @@ func UUIDHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.SendString(uuid)
|
||||
}
|
||||
|
||||
// NotFoundHandler is the API handler used for any requests that do not match an existing route.
|
||||
func NotFoundHandler(ctx *fiber.Ctx) error {
|
||||
return ctx.SendStatus(http.StatusNotFound)
|
||||
}
|
||||
|
||||
19
src/util.go
19
src/util.go
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/mineatar-io/skin-render"
|
||||
)
|
||||
|
||||
// QueryParams is used by most all API routes as options for how the image should be rendered, or how errors should be handled.
|
||||
type QueryParams struct {
|
||||
Scale int `query:"scale"`
|
||||
Download bool `query:"download"`
|
||||
@@ -23,10 +24,12 @@ type QueryParams struct {
|
||||
Fallback bool `query:"fallback"`
|
||||
}
|
||||
|
||||
// FormatUUID returns the UUID string without any dashes.
|
||||
func FormatUUID(uuid string) string {
|
||||
return strings.ToLower(strings.ReplaceAll(uuid, "-", ""))
|
||||
}
|
||||
|
||||
// LookupUUID returns the UUID of a player either by username or UUID, while attempting to use any cached values in the database.
|
||||
func LookupUUID(value string) (string, bool, error) {
|
||||
value = FormatUUID(value)
|
||||
|
||||
@@ -56,13 +59,14 @@ func LookupUUID(value string) (string, bool, error) {
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
if err = r.Set(cacheKey, profile.UUID, config.Cache.UUIDCacheDuration); err != nil {
|
||||
if err = r.Set(cacheKey, profile.UUID, conf.Cache.UUIDCacheDuration); err != nil {
|
||||
return "", true, err
|
||||
}
|
||||
|
||||
return profile.UUID, true, nil
|
||||
}
|
||||
|
||||
// FetchImage fetches the image by the URL and returns it as a parsed image.
|
||||
func FetchImage(url string) (*image.NRGBA, error) {
|
||||
resp, err := http.Get(url)
|
||||
|
||||
@@ -89,6 +93,7 @@ func FetchImage(url string) (*image.NRGBA, error) {
|
||||
return img.(*image.NRGBA), nil
|
||||
}
|
||||
|
||||
// GetPlayerSkin fetches the skin of the Minecraft player by the UUID.
|
||||
func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||
uuid = FormatUUID(uuid)
|
||||
|
||||
@@ -166,12 +171,12 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if err = r.Set(fmt.Sprintf("skin:%s", uuid), encodedSkin, config.Cache.SkinCacheDuration); err != nil {
|
||||
if err = r.Set(fmt.Sprintf("skin:%s", uuid), encodedSkin, conf.Cache.SkinCacheDuration); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if slim {
|
||||
if err = r.Set(fmt.Sprintf("slim:%s", uuid), "true", config.Cache.SkinCacheDuration); err != nil {
|
||||
if err = r.Set(fmt.Sprintf("slim:%s", uuid), "true", conf.Cache.SkinCacheDuration); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
} else {
|
||||
@@ -183,8 +188,8 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||
return skin, slim, nil
|
||||
}
|
||||
|
||||
// This is used instead of `math.Min/Max` because of the
|
||||
// unnecessary coercion from/to float64.
|
||||
// Clamp clamps the input value between the minimum and maximum values.
|
||||
// This method is preferred over `math.Min()` and `math.Max()` to prevent any type coercion between floats and integers.
|
||||
func Clamp(value, min, max int) int {
|
||||
if value > max {
|
||||
return max
|
||||
@@ -197,6 +202,7 @@ func Clamp(value, min, max int) int {
|
||||
return value
|
||||
}
|
||||
|
||||
// EncodePNG encodes the image into PNG format and returns the data as a byte array.
|
||||
func EncodePNG(img image.Image) ([]byte, error) {
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
@@ -207,6 +213,7 @@ func EncodePNG(img image.Image) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// ParseQueryParams parses the query parameters from the request and returns a QueryParams struct, using default values from the provided configuration.
|
||||
func ParseQueryParams(ctx *fiber.Ctx, route RouteConfig) *QueryParams {
|
||||
args := ctx.Context().QueryArgs()
|
||||
|
||||
@@ -238,6 +245,7 @@ func ParseQueryParams(ctx *fiber.Ctx, route RouteConfig) *QueryParams {
|
||||
return response
|
||||
}
|
||||
|
||||
// GetInstanceID returns the INSTANCE_ID environment variable parsed as an unsigned 16-bit integer.
|
||||
func GetInstanceID() (uint16, error) {
|
||||
if instanceID := os.Getenv("INSTANCE_ID"); len(instanceID) > 0 {
|
||||
value, err := strconv.ParseUint(instanceID, 10, 16)
|
||||
@@ -252,6 +260,7 @@ func GetInstanceID() (uint16, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// ParseUserParam returns the user name from the route param, allowing values such as "PassTheMayo.png" to be returned as "PassTheMayo".
|
||||
func ParseUserParam(ctx *fiber.Ctx) string {
|
||||
return strings.Split(ctx.Params("user"), ".")[0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user