Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gin -> net/http + httprouter #34

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ CHANNEL="my-channel"
SUBSCRIBER="my-subscriber"

# Create a HTTP polling subscriber.
curl -w "\n" -X PUT "http://localhost:3099/channel/${CHANNEL}/subscription/polling/${SUBSCRIBER}"
curl -X PUT "http://localhost:3099/channel/${CHANNEL}/subscription/polling/${SUBSCRIBER}"

# Publish message to the channel.
curl -w "\n" -X PUT -H "Content-Type: application/json" \
curl -X PUT -H "Content-Type: application/json" \
-d '{ "hello": "Hi!" }' \
"http://localhost:3099/channel/${CHANNEL}/message/my-first-message"

# Receive messages with HTTP long-polling.
# In this example, this API immediately returns
# because the subscriber already have been received a message.
curl -w "\n" -X GET "http://localhost:3099/channel/${CHANNEL}/subscription/polling/${SUBSCRIBER}?timeout=30s&max=64"
curl -X GET "http://localhost:3099/channel/${CHANNEL}/subscription/polling/${SUBSCRIBER}?timeout=30s&max=64"

ACK_HANDLE="<< set string returned in the above API response >>"

Expand Down
33 changes: 23 additions & 10 deletions server/config/http_server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package config

import (
"fmt"
"regexp"
"strings"

"github.com/saiya/dsps/server/domain"
)

// HTTPServerConfig represents HTTP webserver settings
type HTTPServerConfig struct {
Port int `json:"port" validate:"min=0,max=65535"`
Listen string `json:"listen"`
PathPrefix string `json:"pathPrefix"`
SourceIPHeader string `json:"sourceIpHeader"`
DiscloseAuthRejectionDetail bool `json:"discloseAuthRejectionDetail"`
Port int `json:"port" validate:"min=0,max=65535"`
Listen string `json:"listen"`
PathPrefix string `json:"pathPrefix"`
SourceIPHeader string `json:"sourceIpHeader"`
DiscloseAuthRejectionDetail bool `json:"discloseAuthRejectionDetail"`
DefaultHeaders map[string]string `json:"defaultHeaders"`

LongPollingMaxTimeout domain.Duration `json:"longPollingMaxTimeout"`
GracefulShutdownTimeout domain.Duration `json:"gracefulShutdownTimeout"`
Expand All @@ -30,6 +30,14 @@ var httpServerConfigDefault = HTTPServerConfig{
GracefulShutdownTimeout: makeDuration("5s"),
}

var defaultHeaders = map[string]string{
"X-Frame-Options": `deny`,
"X-Content-Type-Options": `nosniff`,
"Cache-Control": `no-cache, no-store, max-age=0, must-revalidate`,
"Pragma": `no-cache`,
"Expires": `0`,
}

// PostprocessHTTPServerConfig cleanups user supplied config object.
func PostprocessHTTPServerConfig(config *HTTPServerConfig, overrides Overrides) error {
if overrides.Port != 0 {
Expand All @@ -42,11 +50,16 @@ func PostprocessHTTPServerConfig(config *HTTPServerConfig, overrides Overrides)
config.Listen = overrides.Listen
}

// Remove trailing "/", add "/" prefix
config.PathPrefix = regexp.MustCompile(`/$`).ReplaceAllString(config.PathPrefix, "")
if !strings.HasPrefix(config.PathPrefix, "/") {
config.PathPrefix = "/" + config.PathPrefix
if config.DefaultHeaders == nil {
config.DefaultHeaders = make(map[string]string, len(defaultHeaders))
}
for name, value := range defaultHeaders {
if _, ok := config.DefaultHeaders[name]; !ok {
config.DefaultHeaders[name] = value
}
}

// Remove "/" prefix and suffix
config.PathPrefix = strings.TrimPrefix(strings.TrimSuffix(config.PathPrefix, "/"), "/")
return nil
}
30 changes: 24 additions & 6 deletions server/config/http_server_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,33 @@ func TestHttpServerConfigOverride(t *testing.T) {

func TestHttpServerConfigPathPrefix(t *testing.T) {
for _, testcase := range []struct{ source, expected string }{
{source: "", expected: "/"},
{source: "/", expected: "/"},
{source: "foo/bar", expected: "/foo/bar"},
{source: "foo/bar/", expected: "/foo/bar"},
{source: "/foo/bar", expected: "/foo/bar"},
{source: "/foo/bar/", expected: "/foo/bar"},
{source: "", expected: ""},
{source: "/", expected: ""},
{source: "foo/bar", expected: "foo/bar"},
{source: "foo/bar/", expected: "foo/bar"},
{source: "/foo/bar", expected: "foo/bar"},
{source: "/foo/bar/", expected: "foo/bar"},
} {
cfg := HTTPServerConfig{PathPrefix: testcase.source}
assert.NoError(t, PostprocessHTTPServerConfig(&cfg, Overrides{Port: 9876}))
assert.Equal(t, testcase.expected, cfg.PathPrefix)
}
}

func TestDefaultHeaders(t *testing.T) {
cfg := HTTPServerConfig{}
assert.NoError(t, PostprocessHTTPServerConfig(&cfg, Overrides{}))
assert.Equal(t, `nosniff`, cfg.DefaultHeaders["X-Content-Type-Options"]) // default

cfg = HTTPServerConfig{
// Values from config file
DefaultHeaders: map[string]string{
"X-Content-Type-Options": ``, // disable this header
"Strict-Transport-Security": `max-age=31536000 ; includeSubDomains`,
},
}
assert.NoError(t, PostprocessHTTPServerConfig(&cfg, Overrides{}))
assert.Equal(t, ``, cfg.DefaultHeaders["X-Content-Type-Options"])
assert.Equal(t, `max-age=31536000 ; includeSubDomains`, cfg.DefaultHeaders["Strict-Transport-Security"])
assert.Equal(t, `no-cache`, cfg.DefaultHeaders["Pragma"]) // default
}
2 changes: 2 additions & 0 deletions server/doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Configuration items under `http`:
- `discloseAuthRejectionDetail` (boolean, default `false`): Show detail reason of 403 to clients, **do not enable on production**
- `longPollingMaxTimeout` (duration string, default `30s`): Max duration of the [long-polling requests](./interface/subscribe/polling.md#polling-get).
- `gracefulShutdownTimeout` (duration string, default `5s`): Timeout to await end of running requests.
- <a name="defaultHeaders"></a> `defaultHeaders` (string to string map, optional): Always send those response headers
- Server send some headers by default, you can disable them by setting empty string as a value.

## logging configuration block

Expand Down
8 changes: 8 additions & 0 deletions server/doc/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ To ensure webhook security, general outgoing HTTP security practices such as fol
1. Use HTTPS (TLS)
2. Send webhook to only safe destinations
3. Do not send webhook to dynamic domain, domain name should be fixed

## HTTP response headers

DSPS server send some response headers by default but you can override them to more security.

For instance, you can enable `Strict-Transport-Security` by setting the header for each response.

Use [`http.defaultHeaders` configuration item](./config.md#defaultHeaders) to set your custom headers for all responses.
6 changes: 1 addition & 5 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ go 1.15
require (
github.com/Songmu/gocredits v0.2.0
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.4.1
github.com/go-redis/redis/v8 v8.4.0
github.com/goccy/go-yaml v1.8.4
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/uuid v1.1.2
github.com/json-iterator/go v1.1.10 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/julienschmidt/httprouter v1.3.0
github.com/stretchr/testify v1.6.1
github.com/ugorji/go v1.2.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 // indirect
Expand Down
30 changes: 2 additions & 28 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-redis/redis/v8 v8.4.0 h1:J5NCReIgh3QgUJu398hUncxDExN4gMOHI11NVbVicGQ=
Expand All @@ -45,7 +40,6 @@ github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
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=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
Expand All @@ -62,15 +56,12 @@ github.com/google/go-cmp v0.4.0/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.3 h1:x95R7cp+rSeeqAMI2knLtQ0DKlaBhv2NrtrOvafPHRo=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand All @@ -83,14 +74,6 @@ github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
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/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand All @@ -113,14 +96,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.0 h1:6eXlzYLLwZwXroJx9NyqbYcbv/d93twiOzQLDewE6qM=
github.com/ugorji/go v1.2.0/go.mod h1:1ny++pKMXhLWrwWV5Nf+CbOuZJhMoaFD+0GMFfd8fEc=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.0 h1:As6RccOIlbm9wHuWYMlB30dErcI+4WiKWsYsmPkyrUw=
github.com/ugorji/go/codec v1.2.0/go.mod h1:dXvG35r7zTX6QImXOSFhGMmKtX+wJ7VTWzGvYQGIjBs=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opentelemetry.io/otel v0.14.0 h1:YFBEfjCk9MTjaytCNSUkp9Q8lF7QJezA06T71FbQxLQ=
go.opentelemetry.io/otel v0.14.0/go.mod h1:vH5xEuwy7Rts0GNtsCW3HYQoZDY+OmBJ6t1bFGGlxgw=
Expand Down Expand Up @@ -238,7 +213,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
18 changes: 8 additions & 10 deletions server/http/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@ package http
import (
"context"

"github.com/gin-gonic/gin"

"github.com/saiya/dsps/server/domain"
"github.com/saiya/dsps/server/http/endpoints"
"github.com/saiya/dsps/server/http/middleware"
"github.com/saiya/dsps/server/http/router"
"github.com/saiya/dsps/server/logger"
)

// InitEndpoints registers endpoints of the DSPS server
func InitEndpoints(mainCtx context.Context, router gin.IRouter, deps *ServerDependencies) {
endpoints.InitProbeEndpoints(router, deps)
func InitEndpoints(mainCtx context.Context, rt *router.Router, deps *ServerDependencies) {
endpoints.InitProbeEndpoints(rt, deps)

channel := router.Group(
channel := rt.NewGroup(
"/channel/:channelID",
func(ctx *gin.Context) {
logger.ModifyGinContext(ctx).WithStr("channelID", ctx.Param("channelID")).Build()
ctx.Next()
func(ctx context.Context, args router.MiddlewareArgs, next func(context.Context)) {
next(logger.WithAttributes(ctx).WithStr("channelID", args.PS.ByName("channelID")).Build())
},
middleware.NewNormalAuth(mainCtx, deps, func(ctx *gin.Context) (domain.Channel, error) {
id, err := domain.ParseChannelID(ctx.Param("channelID"))
middleware.NewNormalAuth(mainCtx, deps, func(c context.Context, args router.MiddlewareArgs) (domain.Channel, error) {
id, err := domain.ParseChannelID(args.PS.ByName("channelID"))
if err != nil {
return nil, err
}
Expand Down
Loading