Compare commits
No commits in common. "89a3cf0eab751b3287340c9ffe463f18fa65ec3d" and "b875758eab2b250750eb0f6f8ab11934bbaf0bad" have entirely different histories.
89a3cf0eab
...
b875758eab
5 changed files with 24 additions and 34 deletions
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FROM alpine:3.14.1 as alpine
|
||||||
|
RUN apk add -U --no-cache ca-certificates
|
||||||
|
FROM alpine:3.14.1
|
||||||
|
EXPOSE 3000
|
||||||
|
LABEL maintainer="dockerhub@enderware.de"
|
||||||
|
ENV GODEBUG netdns=go
|
||||||
|
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
ADD gitea-attachements-proxy /bin/
|
||||||
|
ENTRYPOINT ["/bin/gitea-attachements-proxy"]
|
3
go.mod
3
go.mod
|
@ -5,7 +5,6 @@ go 1.17
|
||||||
require (
|
require (
|
||||||
code.gitea.io/sdk/gitea v0.15.1
|
code.gitea.io/sdk/gitea v0.15.1
|
||||||
github.com/gofiber/fiber/v2 v2.30.0
|
github.com/gofiber/fiber/v2 v2.30.0
|
||||||
github.com/json-iterator/go v1.1.12
|
|
||||||
github.com/kpango/glg v1.6.10
|
github.com/kpango/glg v1.6.10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,8 +15,6 @@ require (
|
||||||
github.com/hashicorp/go-version v1.4.0 // indirect
|
github.com/hashicorp/go-version v1.4.0 // indirect
|
||||||
github.com/klauspost/compress v1.15.1 // indirect
|
github.com/klauspost/compress v1.15.1 // indirect
|
||||||
github.com/kpango/fastime v1.1.4 // indirect
|
github.com/kpango/fastime v1.1.4 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
|
||||||
github.com/stretchr/testify v1.7.0 // indirect
|
github.com/stretchr/testify v1.7.0 // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasthttp v1.34.0 // indirect
|
github.com/valyala/fasthttp v1.34.0 // indirect
|
||||||
|
|
7
go.sum
7
go.sum
|
@ -10,12 +10,9 @@ github.com/goccy/go-json v0.9.6 h1:5/4CtRQdtsX0sal8fdVhTaiMN01Ri8BExZZ8iRmHQ6E=
|
||||||
github.com/goccy/go-json v0.9.6/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
github.com/goccy/go-json v0.9.6/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||||
github.com/gofiber/fiber/v2 v2.30.0 h1:R928kgJICQkcfIzAjMIQ+U0uOpa0+vTCZLLODeo4M14=
|
github.com/gofiber/fiber/v2 v2.30.0 h1:R928kgJICQkcfIzAjMIQ+U0uOpa0+vTCZLLODeo4M14=
|
||||||
github.com/gofiber/fiber/v2 v2.30.0/go.mod h1:1Ega6O199a3Y7yDGuM9FyXDPYQfv+7/y48wl6WCwUF4=
|
github.com/gofiber/fiber/v2 v2.30.0/go.mod h1:1Ega6O199a3Y7yDGuM9FyXDPYQfv+7/y48wl6WCwUF4=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
|
||||||
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4=
|
github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4=
|
||||||
github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
|
||||||
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
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 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A=
|
||||||
github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||||
|
@ -23,10 +20,6 @@ github.com/kpango/fastime v1.1.4 h1:pus9JgJBg/8Jie3ozayA4yNIV67BUPhbq0wMZY3CtYo=
|
||||||
github.com/kpango/fastime v1.1.4/go.mod h1:tTNDbIo5qL6D7g5vh2YbkyUbOVP2kD/we3rSjN22PMY=
|
github.com/kpango/fastime v1.1.4/go.mod h1:tTNDbIo5qL6D7g5vh2YbkyUbOVP2kD/we3rSjN22PMY=
|
||||||
github.com/kpango/glg v1.6.10 h1:ykvO7lKmfYp9d3jBvIO7UFV5mqp2FYPezC0rAyN1IqA=
|
github.com/kpango/glg v1.6.10 h1:ykvO7lKmfYp9d3jBvIO7UFV5mqp2FYPezC0rAyN1IqA=
|
||||||
github.com/kpango/glg v1.6.10/go.mod h1:Er7L/mFi0MY+Nse2a85sc3kU80cR3Vi3iBKax56r5ng=
|
github.com/kpango/glg v1.6.10/go.mod h1:Er7L/mFi0MY+Nse2a85sc3kU80cR3Vi3iBKax56r5ng=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
||||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
|
||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||||
|
|
31
main.go
31
main.go
|
@ -5,13 +5,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"github.com/kpango/glg"
|
"github.com/kpango/glg"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
|
||||||
|
|
||||||
type Channel int
|
type Channel int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -68,24 +65,22 @@ func getAttachementURL(attachement Attachement) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RegionCounter) countRegion(region string) {
|
func (r *RegionCounter) countRegion(region string) {
|
||||||
glg.Debugf("Region %s", region)
|
glg.Infof("Region %s", region)
|
||||||
r.Lock()
|
glg.Debugf("%+v", r.RegionCount)
|
||||||
defer r.Unlock()
|
|
||||||
if region == "" {
|
if region == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val, ok := r.RegionCount[region]
|
_, ok := r.RegionCount[region]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
glg.Info("New region")
|
||||||
r.RegionCount[region] = 1
|
r.RegionCount[region] = 1
|
||||||
|
glg.Debugf("%+v", r.RegionCount)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.RegionCount[region] = val + 1
|
r.Lock()
|
||||||
}
|
defer r.Unlock()
|
||||||
|
r.RegionCount[region]++
|
||||||
func (r *RegionCounter) getRegionCount() map[string]int {
|
glg.Debugf("%+v", r.RegionCount)
|
||||||
r.RLock()
|
|
||||||
defer r.RUnlock()
|
|
||||||
return r.RegionCount
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -97,8 +92,6 @@ func main() {
|
||||||
GETOnly: true,
|
GETOnly: true,
|
||||||
ServerHeader: "Fiber",
|
ServerHeader: "Fiber",
|
||||||
AppName: "Gitea Attachement Proxy",
|
AppName: "Gitea Attachement Proxy",
|
||||||
JSONEncoder: jsoniter.Marshal,
|
|
||||||
JSONDecoder: jsoniter.Unmarshal,
|
|
||||||
})
|
})
|
||||||
app.Use(recover.New())
|
app.Use(recover.New())
|
||||||
|
|
||||||
|
@ -167,7 +160,11 @@ func main() {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get("/regions", func(c *fiber.Ctx) error {
|
app.Get("/regions", func(c *fiber.Ctx) error {
|
||||||
return c.JSON(regionCounter.getRegionCount())
|
regionCounter.RLock()
|
||||||
|
defer regionCounter.RUnlock()
|
||||||
|
c.JSON(regionCounter.RegionCount)
|
||||||
|
glg.Debugf("%+v", regionCounter.RegionCount)
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Listen(":8080")
|
app.Listen(":8080")
|
||||||
|
|
|
@ -13,22 +13,16 @@ pkgs.buildGo117Module {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
stdenv glibc.static
|
|
||||||
] ++deps;
|
] ++deps;
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
] ++nativeDeps;
|
] ++nativeDeps;
|
||||||
|
|
||||||
tags = [ ];
|
tags = [ ];
|
||||||
ldflags = [
|
|
||||||
"-s" "-w"
|
|
||||||
"-linkmode external"
|
|
||||||
"-extldflags -static"
|
|
||||||
];
|
|
||||||
|
|
||||||
allowGoReference = false;
|
allowGoReference = false;
|
||||||
|
|
||||||
#vendorSha256 = lib.fakeSha256;
|
#vendorSha256 = lib.fakeSha256;
|
||||||
vendorSha256 = "sha256-2UA3WfEN/TxxsBgiEQv6O90k/AJOsy76Di/kbRBJNfY=";
|
vendorSha256 = "sha256-K5EBHiU03DMzD/E4yuCLq6p+G0PU62bR1BHuGtA3KhU=";
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
description = "A Wrapper around the gitea API to get attachments by tags";
|
description = "A Wrapper around the gitea API to get attachments by tags";
|
||||||
|
|
Loading…
Add table
Reference in a new issue