Skip to content

Commit

Permalink
martian: silence force type asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Choraden committed Aug 16, 2023
1 parent a4862f6 commit a2a90b7
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/martian/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewContext(req *http.Request) *Context {
if v == nil {
return nil
}
return v.(*Context)
return v.(*Context) //nolint:forcetypeassert // We know the type.
}

// TestContext builds a new session and associated context and returns the context.
Expand Down
2 changes: 1 addition & 1 deletion internal/martian/h2/h2.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ func (s *streamProcessors) Get(id uint32, dir Direction) Processor {
if !ok {
value, _ = s.processors.LoadOrStore(id, s.create(id))
}
return value.(*Processors).ForDirection(dir)
return value.(*Processors).ForDirection(dir) //nolint:forcetypeassert // The value is always a *Processors.
}
2 changes: 1 addition & 1 deletion internal/martian/h2/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ type outputBuffer struct {
// This is not thread-safe. The caller should be holding `relay.flowMu`.
func (w *outputBuffer) emitEligibleFrames(output chan queuedFrame, connectionWindowSize *int) {
for e := w.queue.Front(); e != nil; {
f := e.Value.(queuedFrame)
f := e.Value.(queuedFrame) //nolint:forcetypeassert // e.Value is always a queuedFrame.
if f.flowControlSize() > *connectionWindowSize || f.flowControlSize() > w.windowSize {
break
}
Expand Down
4 changes: 2 additions & 2 deletions internal/martian/h2/testing/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func New(spf []h2.StreamProcessorFactory) (*Fixture, error) {
if err != nil {
return nil, fmt.Errorf("creating listener for proxy; %w", err)
}
proxyPort = f.proxyListener.Addr().(*net.TCPAddr).Port
proxyPort = f.proxyListener.Addr().(*net.TCPAddr).Port //nolint:forcetypeassert // It's a TCPAddr.
}
proxyTarget := hostname + ":" + strconv.Itoa(proxyPort)
// Sets the HTTPS_PROXY environment variable so that http requests will go through the proxy.
Expand All @@ -118,7 +118,7 @@ func New(spf []h2.StreamProcessorFactory) (*Fixture, error) {
f.proxy.Serve(f.proxyListener)
}()

port := lis.Addr().(*net.TCPAddr).Port
port := lis.Addr().(*net.TCPAddr).Port //nolint:forcetypeassert // It's a TCPAddr.
target := hostname + ":" + strconv.Itoa(port)

fmt.Printf("server at %s\n", target)
Expand Down
2 changes: 1 addition & 1 deletion internal/martian/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func addTrailerHeader(rw http.ResponseWriter, tr http.Header) int {
}

func copyBody(w io.Writer, body io.ReadCloser) error {
bufp := copyBufPool.Get().(*[]byte)
bufp := copyBufPool.Get().(*[]byte) //nolint:forcetypeassert // It's *[]byte.
buf := *bufp
defer copyBufPool.Put(bufp)

Expand Down
2 changes: 1 addition & 1 deletion internal/martian/header/via_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (m *ViaModifier) ModifyResponse(res *http.Response) error {
res.StatusCode = 400
res.Status = http.StatusText(http.StatusBadRequest)

return err.(error)
return err.(error) //nolint:forcetypeassert // viaLoopKey is always an error.
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/martian/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ var copyBufPool = sync.Pool{
}

func copySync(name string, w io.Writer, r io.Reader, donec chan<- bool) {
bufp := copyBufPool.Get().(*[]byte)
bufp := copyBufPool.Get().(*[]byte) //nolint:forcetypeassert // It's *[]byte.
buf := *bufp
defer copyBufPool.Put(bufp)

Expand Down
2 changes: 1 addition & 1 deletion internal/martian/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestIntegrationHTTP(t *testing.T) {
ctx := NewContext(res.Request)
v, _ := ctx.Get("martian.test")

res.Header.Set("Martian-Test", v.(string))
res.Header.Set("Martian-Test", v.(string)) //nolint:forcetypeassert // Test only.
})

p.SetRequestModifier(tm)
Expand Down

0 comments on commit a2a90b7

Please sign in to comment.