~bigbes/core-go

ref: 3686f7e2cb0118367fdc74fd20b2e115fb90bb54 core-go/server/server.go -rw-r--r-- 10.0 KiB
e5f2298c — Drew DeVault 1 year, 18 days ago
server: log GraphQL queries if running in debug mode
a8516055 — Conrad Hoffmann 1 year, 26 days ago
server: handle CORS in server

Currently CORS is handled in nginx in front of the API. That setup is
not very suitable for Kubernetes. Instead, handle CORS here, so we do
not need any intermediaries between the ingress and the APIs.

The CORS settings are taken from sr.ht-nginx/graphql.conf [1]

[1] https://git.sr.ht/~sircmpwn/sr.ht-nginx/tree/master/item/graphql.conf
ba01be84 — Conrad Hoffmann 1 year, 1 month ago
server: replace deprecated gqlgen code

Most of the gqlgen/handler package, specifically also
`handler.GraphQL()`, has been deprecated [1]. The documentation of the
new package [2] is a bit lacking, but some stuff is covered in the
reference docs [3] [4], and some in the examples [5].

[1] https://pkg.go.dev/github.com/99designs/gqlgen@v0.17.36/handler#GraphQL
[2] https://pkg.go.dev/github.com/99designs/gqlgen@v0.17.36/graphql/handler
[3] https://gqlgen.com/reference/errors/#the-panic-handler
[4] https://gqlgen.com/reference/complexity/#limiting-query-complexity
[5] https://github.com/99designs/gqlgen/blob/master/_examples/fileupload/server/server.go
bdb0f7e8 — Drew DeVault 1 year, 1 month ago
server: disable logging for release mode

This was partially implemented a while ago but we missed the main point
where it matters.
79dad627 — Drew DeVault 1 year, 4 months ago
server: add pprof endpoint

This adds a pprof endpoint to all SourceHut APIs. It picks an
OS-assigned port on localhost to run it on and prints this port to
stdout. This ensures a unique port is selected even if several APIs are
running on a single host.
0bea6849 — Drew DeVault 1 year, 5 months ago
server: enable request logging only in debug mode

To improve the signal:noise ratio in the production logs.
redis: avoid building UniversalOptions for standard mode

This makes it support all options that go-redis recognizes in ParseURL,
by constructing a standard client directly instead of building
UniversalOptions ourselves.
e4b0261f — Drew DeVault 1 year, 6 months ago
Export webhooks public key via api-meta.json
17315205 — Robin Jarry 1 year, 8 months ago
config: factorize integer parsing

Add a new GetInt() function to parse an integer value from a parsed
ini.File. Use that function instead of duplicated code.

Signed-off-by: Robin Jarry <robin@jarry.cc>
7457c44b — Robin Jarry 1 year, 8 months ago
treewide: update to new multi worker dowork api

The work.Queue() implementation has changed and now allows scheduling
tasks from multiple goroutines in parallel. Also, it requires a new
argument for limiting the queue buffer size in order to apply back
pressure.

Define new configuration variables to allow tuning the queue sizes and
number of workers per service:

  [mail]
  # Maximum size of the outgoing email queue (default 512).
  egress-queue-size = 512

  [$service_name]
  # Number of parallel workers per queue (default 1).
  # There are multiple queues (for egress email, webhooks, etc.).
  # This setting is applied on a per-queue basis.
  queue-workers = 1

  [webhooks]
  # Maximum size of the webhooks queue (default 512).
  queue-size = 512

Use these new settings to configure the queues and workers accordingly.

Fix unit tests as well.

Link: https://git.sr.ht/~sircmpwn/dowork/commit/95719cfc0118
Signed-off-by: Robin Jarry <robin@jarry.cc>
e1b63989 — Conrad Hoffmann 1 year, 9 months ago
redis: use UniveralClient, support sentinel mode

This commit switches the redis client to using a UniversalClient [1],
which can operate in standard, cluster, or failover (sentinel) mode.

It also implements basic support for having (multiple)
`redis+sentinel://` URLs as connection URL in the config (e.g. for
`redis-host`).

This is the Go equivalent of the proposed Python patch [2]. It supports
the same examples given there.

[1] https://pkg.go.dev/github.com/go-redis/redis/v8#UniversalClient
[2] https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/55521
9833a827 — Drew DeVault 1 year, 9 months ago
server: add AnonRouter function

To expose anonymous (unauthenticated) routing to downstream core-go
users.
8f9aa9d5 — Drew DeVault 1 year, 9 months ago
server: fix playground on config.Debug

A recent change made it so that the playground required authentication
to access in debug mode; this moves it under the other auth-free
endpoints.
0d6031be — Conrad Hoffmann 1 year, 11 months ago
server: use routing groups

Instead of hardcoding some exceptions in the auth middleware, use a
different routing group for routes that do not require auth. Makes the
auth middleware more generic and also removes a lot of unneccessary
middleware processing from routes that don't need it.

For now, the added group is not accessible from outside the module, but
if the need arises, this might be an option.
d2ad494f — Simon Ser 2 years ago
Migrate to chi v5

v1 is not maintained anymore.
144fc447 — Drew DeVault 3 years ago
server: register SQL collector

Missed this step
fa27910a — Drew DeVault 3 years ago
Add prometheus SQL connection stats

Also updates the prometheus client_go library
0b2fef24 — Conrad Hoffmann 4 years ago
Normalize remote address before saving to context

One cause for https://todo.sr.ht/~sircmpwn/meta.sr.ht/193 was that code
performing this sanitization was in multiple places, and a fix was not
applied in all places. There is no reasonable expectation for the port
to be present anyways, e.g. if the address is taken from a trusted
reverse proxy's header. Hence, perform the normalization here, so that
the code doing this in applications can be simplified.

Note that this does not yet fix the below ticket, it will just make the
fix easier.

References: https://todo.sr.ht/~sircmpwn/meta.sr.ht/193
8c2729f4 — Adnan Maolood 4 years ago
email.EnqueueStd: Don't overwrite headers

Sometimes we need to specify the Message-Id, From, and Reply-To headers
(e.g. for todo.sr.ht ticket notifications). Don't overwrite these
headers if they are present.
dea4ef29 — Drew DeVault 4 years ago
server: move auth middlware ahead of RealIP

So that @internal auth can correctly test against internal-ipnet.
Next