Skip to content

How to write a response middleware #2706

Answered by aldas
JobberRT asked this question in Q&A
Discussion options

You must be logged in to vote

if it is only body then probably you can take https://github.com/labstack/echo/blob/master/middleware/body_dump.go middleware and create writer than encrypts responses and replace request body reader with something that decrypts into memory and replaces body.

reading https://groups.google.com/g/golang-nuts/c/fIOM5sZto0I point to this example that has streamWriter https://go.dev/play/p/4CX1J_IYqk

package main

import (
	"bytes"
	"compress/gzip"
	"crypto/aes"
	"crypto/cipher"
	"fmt"
	"io"
)

func main() {
	key := []byte("example key 1234")
	httpBody := bytes.NewBufferString("the body")

	block, err := aes.NewCipher(key)
	if err != nil {
		panic(err)
	}

	var iv [aes.BlockSize]byte
	stream := 

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@aldas
Comment options

Answer selected by JobberRT
@JobberRT
Comment options

@aldas
Comment options

@JobberRT
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants