From 57b8b17e427624e837a042e1f1f0e641a8b26d8f Mon Sep 17 00:00:00 2001 From: Jacob Gunther Date: Mon, 11 Jul 2022 11:27:43 -0500 Subject: [PATCH] Clean up code, remove Prometheus --- go.mod | 14 ++-- go.sum | 47 ++++++----- src/main.go | 48 +---------- src/routes/body.go | 205 +++++++-------------------------------------- src/routes/face.go | 45 ++-------- src/routes/head.go | 45 ++-------- src/routes/ping.go | 11 --- src/routes/skin.go | 30 +------ src/routes/uuid.go | 20 +---- src/util/util.go | 14 ++++ 10 files changed, 98 insertions(+), 381 deletions(-) diff --git a/go.mod b/go.mod index d495958..1d66aaa 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/joho/godotenv v1.4.0 github.com/mineatar-io/skin-render v1.0.1 github.com/mineatar-io/yggdrasil v1.0.0 - github.com/prometheus/client_golang v1.12.1 - github.com/valyala/fasthttp v1.34.0 - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b + github.com/prometheus/client_golang v1.12.2 + github.com/valyala/fasthttp v1.38.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -19,13 +19,13 @@ require ( github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/klauspost/compress v1.15.1 // indirect + github.com/klauspost/compress v1.15.7 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/prometheus/client_model v0.2.0 // indirect - github.com/prometheus/common v0.32.1 // indirect + github.com/prometheus/common v0.35.0 // indirect github.com/prometheus/procfs v0.7.3 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - golang.org/x/image v0.0.0-20220321031419-a8550c1d254a // indirect - golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect + golang.org/x/image v0.0.0-20220617043117-41969df76e82 // indirect + golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d // indirect google.golang.org/protobuf v1.28.0 // indirect ) diff --git a/go.sum b/go.sum index 0874119..7999ecf 100644 --- a/go.sum +++ b/go.sum @@ -72,11 +72,11 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-kit/log v0.2.0/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= -github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= 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-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -120,9 +120,8 @@ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -133,6 +132,7 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -140,6 +140,7 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +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/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -153,8 +154,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.15.1 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A= -github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/klauspost/compress v1.15.7 h1:7cgTQxJCU/vy+oP/E3B9RGbQTgbiVzIJWIKOLoAsPok= +github.com/klauspost/compress v1.15.7/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -181,14 +182,15 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= -github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +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/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -197,8 +199,9 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +github.com/prometheus/client_golang v1.12.2 h1:51L9cDoUHVrXx4zWYlcLQIZ+d+VXHgqnYKkIuq4g/34= +github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -207,8 +210,9 @@ github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6T github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= -github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= +github.com/prometheus/common v0.35.0 h1:Eyr+Pw2VymWejHqCugNaQXkAi6KayVNxaHeu6khmFBE= +github.com/prometheus/common v0.35.0/go.mod h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= @@ -227,8 +231,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 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.34.0 h1:d3AAQJ2DRcxJYHm7OXNXtXt2as1vMDfxeIcFvhmGGm4= -github.com/valyala/fasthttp v1.34.0/go.mod h1:epZA5N+7pY6ZaEKRmstzOuYJx9HI8DI1oaCGZpdH4h0= +github.com/valyala/fasthttp v1.38.0 h1:yTjSSNjuDi2PPvXY2836bIwLmiTS2T4T9p1coQshpco= +github.com/valyala/fasthttp v1.38.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -258,10 +262,9 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.0.0-20220302094943-723b81ca9867 h1:TcHcE0vrmgzNH1v3ppjcMGbhG5+9fMuvOmUYwNEF4q4= golang.org/x/image v0.0.0-20220302094943-723b81ca9867/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/image v0.0.0-20220321031419-a8550c1d254a h1:LnH9RNcpPv5Kzi15lXg42lYMPUf0x8CuPv1YnvBWZAg= -golang.org/x/image v0.0.0-20220321031419-a8550c1d254a/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/image v0.0.0-20220617043117-41969df76e82 h1:KpZB5pUSBvrHltNEdK/tw0xlPeD13M6M6aGP32gKqiw= +golang.org/x/image v0.0.0-20220617043117-41969df76e82/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -314,6 +317,7 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -322,6 +326,7 @@ golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4Iltr golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -376,10 +381,9 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc 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-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= -golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d h1:/m5NbqQelATgoSPVC2Z23sR4kVNokFwDDyWh/3rGY+I= +golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d/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/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -513,7 +517,6 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= @@ -533,8 +536,8 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/src/main.go b/src/main.go index 3fe4292..37fe86c 100644 --- a/src/main.go +++ b/src/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "log" - "net/http" "os" "strconv" "time" @@ -14,26 +13,14 @@ import ( "github.com/mineatar-io/api-server/src/redis" "github.com/mineatar-io/api-server/src/routes" "github.com/mineatar-io/api-server/src/util" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/valyala/fasthttp" ) var ( - host string = "127.0.0.1" - port uint16 = 3000 - prometheusHost string = "127.0.0.1" - prometheusPort uint16 = 3001 - config *conf.Configuration = &conf.Configuration{} - r *redis.Redis = &redis.Redis{} -) - -var ( - requestCountMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "request_count", - Help: "The total number of requests received", - }) + host string = "127.0.0.1" + port uint16 = 3000 + config *conf.Configuration = &conf.Configuration{} + r *redis.Redis = &redis.Redis{} ) func init() { @@ -55,11 +42,6 @@ func init() { if value, ok := os.LookupEnv("HOST"); ok { host = value - prometheusHost = value - } - - if value, ok := os.LookupEnv("PROM_HOST"); ok { - prometheusHost = value } if value, ok := os.LookupEnv("PORT"); ok { @@ -70,17 +52,6 @@ func init() { } port = uint16(parsedValue) - prometheusPort = uint16(parsedValue + 1) - } - - if value, ok := os.LookupEnv("PROM_PORT"); ok { - parsedValue, err := strconv.ParseUint(value, 10, 16) - - if err != nil { - log.Fatal(err) - } - - prometheusPort = uint16(parsedValue) } routes.Init(r, config) @@ -98,19 +69,10 @@ func middleware(next fasthttp.RequestHandler) fasthttp.RequestHandler { log.Printf("%s %s (%s) - %s\n", ctx.Method(), ctx.URI(), ctx.RemoteAddr(), ctx.UserAgent()) } - requestCountMetric.Inc() - next(ctx) } } -func metrics() { - log.Printf("Prometheus listening on %s:%d\n", prometheusHost, prometheusPort) - - http.Handle("/metrics", promhttp.Handler()) - http.ListenAndServe(fmt.Sprintf("%s:%d", prometheusHost, prometheusPort), nil) -} - func main() { defer r.Close() @@ -129,7 +91,5 @@ func main() { log.Printf("Listening on %s:%d\n", host, port) - go metrics() - log.Fatal(fasthttp.ListenAndServe(fmt.Sprintf("%s:%d", host, port), middleware(router.Handler))) } diff --git a/src/routes/body.go b/src/routes/body.go index 78db397..b01a297 100644 --- a/src/routes/body.go +++ b/src/routes/body.go @@ -7,57 +7,10 @@ import ( "github.com/mineatar-io/api-server/src/util" "github.com/mineatar-io/skin-render" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" "github.com/valyala/fasthttp" ) -var ( - requestFullBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "full_body_request_count", - Help: "The amount of full body requests", - }) - renderFullBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "full_body_render_count", - Help: "The amount of full body renders", - }) - requestFrontBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "front_body_request_count", - Help: "The amount of front body requests", - }) - renderFrontBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "front_body_render_count", - Help: "The amount of front body renders", - }) - requestBackBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "back_body_request_count", - Help: "The amount of back body requests", - }) - renderBackBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "back_body_render_count", - Help: "The amount of back body renders", - }) - requestLeftBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "left_body_request_count", - Help: "The amount of left body requests", - }) - renderLeftBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "left_body_render_count", - Help: "The amount of left body renders", - }) - requestRightBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "right_body_request_count", - Help: "The amount of right body requests", - }) - renderRightBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "right_body_render_count", - Help: "The amount of right body renders", - }) -) - func FullBodyHandler(ctx *fasthttp.RequestCtx) { - requestFullBodyMetric.Inc() - user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.FullBody) @@ -65,17 +18,13 @@ func FullBodyHandler(ctx *fasthttp.RequestCtx) { uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if !ok && !opts.Fallback { - ctx.SetStatusCode(http.StatusNotFound) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } @@ -86,10 +35,7 @@ func FullBodyHandler(ctx *fasthttp.RequestCtx) { cache, ok, err := r.GetBytes(cacheKey) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -114,10 +60,7 @@ func FullBodyHandler(ctx *fasthttp.RequestCtx) { rawSkin, slim, err := util.GetPlayerSkin(uuid) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -132,24 +75,16 @@ func FullBodyHandler(ctx *fasthttp.RequestCtx) { log.Printf("Rendered full body image for '%s'\n", uuid) } - renderFullBodyMetric.Inc() - data, err := util.EncodePNG(render) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -164,8 +99,6 @@ func FullBodyHandler(ctx *fasthttp.RequestCtx) { } func FrontBodyHandler(ctx *fasthttp.RequestCtx) { - requestFrontBodyMetric.Inc() - user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.FrontBody) @@ -173,17 +106,13 @@ func FrontBodyHandler(ctx *fasthttp.RequestCtx) { uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if !ok && !opts.Fallback { - ctx.SetStatusCode(http.StatusNotFound) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } @@ -194,10 +123,7 @@ func FrontBodyHandler(ctx *fasthttp.RequestCtx) { cache, ok, err := r.GetBytes(cacheKey) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -222,10 +148,7 @@ func FrontBodyHandler(ctx *fasthttp.RequestCtx) { rawSkin, slim, err := util.GetPlayerSkin(uuid) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -240,24 +163,16 @@ func FrontBodyHandler(ctx *fasthttp.RequestCtx) { log.Printf("Rendered front body image for '%s'\n", uuid) } - renderFrontBodyMetric.Inc() - data, err := util.EncodePNG(render) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -272,8 +187,6 @@ func FrontBodyHandler(ctx *fasthttp.RequestCtx) { } func BackBodyHandler(ctx *fasthttp.RequestCtx) { - requestBackBodyMetric.Inc() - user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.BackBody) @@ -281,17 +194,13 @@ func BackBodyHandler(ctx *fasthttp.RequestCtx) { uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if !ok && !opts.Fallback { - ctx.SetStatusCode(http.StatusNotFound) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } @@ -302,10 +211,7 @@ func BackBodyHandler(ctx *fasthttp.RequestCtx) { cache, ok, err := r.GetBytes(cacheKey) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -330,10 +236,7 @@ func BackBodyHandler(ctx *fasthttp.RequestCtx) { rawSkin, slim, err := util.GetPlayerSkin(uuid) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -348,24 +251,16 @@ func BackBodyHandler(ctx *fasthttp.RequestCtx) { log.Printf("Rendered back body image for '%s'\n", uuid) } - renderBackBodyMetric.Inc() - data, err := util.EncodePNG(render) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -380,8 +275,6 @@ func BackBodyHandler(ctx *fasthttp.RequestCtx) { } func LeftBodyHandler(ctx *fasthttp.RequestCtx) { - requestLeftBodyMetric.Inc() - user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.LeftBody) @@ -389,17 +282,13 @@ func LeftBodyHandler(ctx *fasthttp.RequestCtx) { uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if !ok && !opts.Fallback { - ctx.SetStatusCode(http.StatusNotFound) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } @@ -410,10 +299,7 @@ func LeftBodyHandler(ctx *fasthttp.RequestCtx) { cache, ok, err := r.GetBytes(cacheKey) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -438,10 +324,7 @@ func LeftBodyHandler(ctx *fasthttp.RequestCtx) { rawSkin, slim, err := util.GetPlayerSkin(uuid) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -456,24 +339,16 @@ func LeftBodyHandler(ctx *fasthttp.RequestCtx) { log.Printf("Rendered left body image for '%s'\n", uuid) } - renderLeftBodyMetric.Inc() - data, err := util.EncodePNG(render) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -488,8 +363,6 @@ func LeftBodyHandler(ctx *fasthttp.RequestCtx) { } func RightBodyHandler(ctx *fasthttp.RequestCtx) { - requestRightBodyMetric.Inc() - user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.RightBody) @@ -497,17 +370,13 @@ func RightBodyHandler(ctx *fasthttp.RequestCtx) { uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if !ok && !opts.Fallback { - ctx.SetStatusCode(http.StatusNotFound) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } @@ -518,10 +387,7 @@ func RightBodyHandler(ctx *fasthttp.RequestCtx) { cache, ok, err := r.GetBytes(cacheKey) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -546,10 +412,7 @@ func RightBodyHandler(ctx *fasthttp.RequestCtx) { rawSkin, slim, err := util.GetPlayerSkin(uuid) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -564,24 +427,16 @@ func RightBodyHandler(ctx *fasthttp.RequestCtx) { log.Printf("Rendered right body image for '%s'\n", uuid) } - renderRightBodyMetric.Inc() - data, err := util.EncodePNG(render) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } diff --git a/src/routes/face.go b/src/routes/face.go index b7aff44..c2687d4 100644 --- a/src/routes/face.go +++ b/src/routes/face.go @@ -7,25 +7,10 @@ import ( "github.com/mineatar-io/api-server/src/util" "github.com/mineatar-io/skin-render" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" "github.com/valyala/fasthttp" ) -var ( - requestFaceMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "face_request_count", - Help: "The amount of face requests", - }) - renderFaceMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "face_render_count", - Help: "The amount of face renders", - }) -) - func FaceHandler(ctx *fasthttp.RequestCtx) { - requestFaceMetric.Inc() - user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.Face) @@ -33,17 +18,13 @@ func FaceHandler(ctx *fasthttp.RequestCtx) { uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if !ok && !opts.Fallback { - ctx.SetStatusCode(http.StatusNotFound) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } @@ -54,10 +35,7 @@ func FaceHandler(ctx *fasthttp.RequestCtx) { cache, ok, err := r.GetBytes(cacheKey) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -82,10 +60,7 @@ func FaceHandler(ctx *fasthttp.RequestCtx) { rawSkin, slim, err := util.GetPlayerSkin(uuid) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -100,24 +75,16 @@ func FaceHandler(ctx *fasthttp.RequestCtx) { log.Printf("Rendered face image for '%s'\n", uuid) } - renderFaceMetric.Inc() - data, err := util.EncodePNG(render) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } diff --git a/src/routes/head.go b/src/routes/head.go index e375a6f..30f594f 100644 --- a/src/routes/head.go +++ b/src/routes/head.go @@ -7,25 +7,10 @@ import ( "github.com/mineatar-io/api-server/src/util" "github.com/mineatar-io/skin-render" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" "github.com/valyala/fasthttp" ) -var ( - requestHeadMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "head_request_count", - Help: "The amount of head requests", - }) - renderHeadMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "head_render_count", - Help: "The amount of head renders", - }) -) - func HeadHandler(ctx *fasthttp.RequestCtx) { - requestHeadMetric.Inc() - user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.Head) @@ -33,17 +18,13 @@ func HeadHandler(ctx *fasthttp.RequestCtx) { uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if !ok && !opts.Fallback { - ctx.SetStatusCode(http.StatusNotFound) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } @@ -54,10 +35,7 @@ func HeadHandler(ctx *fasthttp.RequestCtx) { cache, ok, err := r.GetBytes(cacheKey) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -82,10 +60,7 @@ func HeadHandler(ctx *fasthttp.RequestCtx) { rawSkin, slim, err := util.GetPlayerSkin(uuid) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -100,24 +75,16 @@ func HeadHandler(ctx *fasthttp.RequestCtx) { log.Printf("Rendered head image for '%s'\n", uuid) } - renderHeadMetric.Inc() - data, err := util.EncodePNG(render) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if err = r.Set(cacheKey, data, config.Cache.RenderCacheDuration); err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } diff --git a/src/routes/ping.go b/src/routes/ping.go index 271daf8..631d9cc 100644 --- a/src/routes/ping.go +++ b/src/routes/ping.go @@ -1,20 +1,9 @@ package routes import ( - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" "github.com/valyala/fasthttp" ) -var ( - pingRequestMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "ping_request_count", - Help: "The amount of ping requests", - }) -) - func PingHandler(ctx *fasthttp.RequestCtx) { - pingRequestMetric.Inc() - ctx.SetBodyString("Pong!") } diff --git a/src/routes/skin.go b/src/routes/skin.go index ccac733..e805b95 100644 --- a/src/routes/skin.go +++ b/src/routes/skin.go @@ -2,22 +2,12 @@ package routes import ( "fmt" - "log" "net/http" "github.com/mineatar-io/api-server/src/util" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" "github.com/valyala/fasthttp" ) -var ( - requestRawSkinMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "raw_skin_request_count", - Help: "The amount of raw skin requests", - }) -) - func SkinHandler(ctx *fasthttp.RequestCtx) { user := ctx.UserValue("user").(string) @@ -26,17 +16,13 @@ func SkinHandler(ctx *fasthttp.RequestCtx) { uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } if !ok && !opts.Fallback { - ctx.SetStatusCode(http.StatusNotFound) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } @@ -44,10 +30,7 @@ func SkinHandler(ctx *fasthttp.RequestCtx) { rawSkin, _, err := util.GetPlayerSkin(uuid) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -55,10 +38,7 @@ func SkinHandler(ctx *fasthttp.RequestCtx) { data, err := util.EncodePNG(rawSkin) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } @@ -67,8 +47,6 @@ func SkinHandler(ctx *fasthttp.RequestCtx) { ctx.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, user)) } - requestRawSkinMetric.Inc() - ctx.SetContentType("image/png") ctx.SetBody(data) } diff --git a/src/routes/uuid.go b/src/routes/uuid.go index 6695644..e709f79 100644 --- a/src/routes/uuid.go +++ b/src/routes/uuid.go @@ -1,41 +1,25 @@ package routes import ( - "log" "net/http" "github.com/mineatar-io/api-server/src/util" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" "github.com/valyala/fasthttp" ) -var ( - uuidLookupMetric = promauto.NewCounter(prometheus.CounterOpts{ - Name: "uuid_lookup_request_count", - Help: "The amount of UUID lookup requests", - }) -) - func UUIDHandler(ctx *fasthttp.RequestCtx) { user := ctx.UserValue("user").(string) uuid, ok, err := util.LookupUUID(user) if err != nil { - log.Println(err) - - ctx.SetStatusCode(http.StatusInternalServerError) - ctx.SetBodyString(http.StatusText(http.StatusInternalServerError)) + util.WriteError(ctx, err, http.StatusInternalServerError) return } - uuidLookupMetric.Inc() - if !ok { - ctx.SetStatusCode(404) - ctx.SetBodyString(http.StatusText(http.StatusNotFound)) + util.WriteError(ctx, nil, http.StatusNotFound) return } diff --git a/src/util/util.go b/src/util/util.go index e349742..053ef07 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -285,3 +285,17 @@ func ParseQueryParams(ctx *fasthttp.RequestCtx, route conf.RouteConfig) *QueryPa return response } + +func WriteError(ctx *fasthttp.RequestCtx, err error, statusCode int, body ...string) { + ctx.SetStatusCode(statusCode) + + if len(body) > 0 { + ctx.SetBodyString(body[0]) + } else { + ctx.SetBodyString(http.StatusText(statusCode)) + } + + if err != nil { + log.Println(err) + } +}