Introduce ocis-pkg/RegisterChiMethodOnce
- Dominant language
- Go
- Stars
- 2.1k
- Forks
- 274
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 103
Description
We should use an `ocis-pkg/chi RegisterMethodOnce(method string)` function that executes the chi call once per method. That would be a cleaner solution than the `MethodNotAllowed` workaround: we can then propery register routes ... or we submit an upstream Fix, duh ...
Related:
* https://github.com/owncloud/ocis/pull/3662
* https://github.com/owncloud/ocis/pull/6921
Our current workaround might have sideeffects in the future: https://github.com/go-chi/chi/pull/776
Hm from the original workaround in #3662:
> chi.RegisterMethod writes to a global map. Other parts of chi read that map and since we start multiple chi router in different goroutines we concurrently read/write to the map which is not valid and results in panics
These other parts are Method and MethodFunc calls, which try to read from the global map. Depending on the order in which services are started the webdav or proxy service might write to the chi `methodMap` while another service is trying to register a route and as a result reading from the `methodMap` in setEndpoint ...
hm, the chi examples just use init:
https://github.com/go-chi/chi/blob/master/_examples/custom-method/main.go
```go
func init() {
chi.RegisterMethod("LINK")
chi.RegisterMethod("UNLINK")
chi.RegisterMethod("WOOHOO")
}
```
Contributor guide
Assessment
This issue has not been assessed yet.