MCPcopy Index your code
hub / github.com/HereMobilityDevelopers/mediary

github.com/HereMobilityDevelopers/mediary @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
22 symbols 58 edges 4 files 4 documented · 18%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

mediary

Add interceptors to http.Client and you will be able to * Dump request and/or response to a Log * Alter your requests before they are sent or responses before they are returned * Add Tracing information using Opentracing/Jaeger * Send metrics to statsd

All this and more while using a "regular" http.Client

Usage

var client *http.Client
client = mediary.Init().AddInterceptors(your interceptor).Build()
client.Get("https://golang.org")

Dump Example

client := mediary.Init().AddInterceptors(dumpInterceptor).Build()
client.Get("https://golang.org")

func dumpInterceptor(req *http.Request, handler mediary.Handler) (*http.Response, error) {
    if bytes, err := httputil.DumpRequestOut(req, true); err == nil {
        fmt.Printf("%s", bytes)

        //GET / HTTP/1.1
        //Host: golang.org
        //User-Agent: Go-http-client/1.1
        //Accept-Encoding: gzip
    }
    return handler(req)
}

Interceptor

Interceptor is a function

type Interceptor func(http.Request, Handler) (http.Response, error)

Handler is just an alias to http.Roundtripper function called RoundTrip

type Handler func(http.Request) (http.Response, error)

Multiple interceptors

It's possible to chain interceptors

client := mediary.Init().
    AddInterceptors(First Interceptor, Second Interceptor).
    AddInterceptors(Third Interceptor).
    Build()

This is how it actually works - First Intereptor: Request - Second Interceptor: Request - Third Interceptor: Request - Handler <-- Actual http call - Third Interceptor: Response - Second Interceptor: Response - First Interceptor: Response

Using custom client/transport

If you already have a pre-configured http.Client you can use it as well

yourClient := &http.Client{}
yourClientWithInterceptor := mediary.Init().
    WithPreconfiguredClient(yourClient).
    AddInterceptors(your interceptor).
    Build()

Read this for more information

Extension points exported contracts — how you extend this code

Builder (Interface)
Builder is a builder interface to help guide and create a mediary instance [1 implementers]
config.go
Handler (FuncType)
Handler is just an alias to http.RoundTriper.RoundTrip function
config.go
Interceptor (FuncType)
Interceptor is a user defined function that can alter a request before it's sent and/or alter a response before it's ret
config.go

Core symbols most depended-on inside this repo

Build
called by 4
config.go
Init
called by 4
config.go
AddInterceptors
called by 2
config.go
WithPreconfiguredClient
called by 2
config.go
prepareCustomRoundTripper
called by 1
mediary.go
uniteInterceptors
called by 1
mediary.go
AddInterceptors
called by 0
config.go
WithPreconfiguredClient
called by 0
config.go

Shape

Function 9
Method 7
Struct 3
FuncType 2
Interface 1

Languages

Go100%

Modules by API surface

config.go12 symbols
mediary_test.go4 symbols
mediary.go4 symbols
examples/dump_test.go2 symbols

For agents

$ claude mcp add mediary \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page