Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( // Gzip provides faster compression methods than the standard library // built-in to go-connect. // Expected performance is ~200MB/s on JSON streams. // Size reduction is ~85% on JSON stream. Gzip = "gzip" // Zstandard uses Zstandard compression, // but with limited window sizes. // Generally Zstandard compresses better and is faster than gzip. // Expected performance is ~300MB/s on JSON streams. // Size ~35% smaller than gzip on JSON stream. Zstandard = "zstd" // Snappy uses Google snappy format. // Expected performance is ~550MB/s on JSON streams. // Size ~50% bigger than gzip on JSON stream. Snappy = "snappy" // S2 provides better compression than Snappy at similar or better speeds. // Expected performance is ~750MB/s on JSON streams. // Size ~2% bigger than gzip on JSON stream. S2 = "s2" )
Variables ¶
This section is empty.
Functions ¶
func WithAll ¶
WithAll returns the client and handler option for all compression methods. Order of preference is S2, Snappy, Zstandard, Gzip.
Example ¶
// Get the client and server option for all compressors... opts := compress.WithAll(compress.LevelBalanced) // Create a server. _, h := pingv1connect.NewPingServiceHandler(&pingServer{}, opts) srv := httptest.NewServer(h) client := pingv1connect.NewPingServiceClient( http.DefaultClient, srv.URL, opts, // Compress requests with S2. connect.WithSendCompression(compress.S2), ) req := connect.NewRequest(&pingv1.PingRequest{ Number: 42, }) req.Header().Set("Some-Header", "hello from connect") res, err := client.Ping(context.Background(), req) if err != nil { log.Fatalln(err) } fmt.Println("The answer is", res.Msg) fmt.Println(res.Header().Get("Some-Other-Header"))
Output: hello from connect The answer is number:42 hello!
Types ¶
type Level ¶
type Level int
Level provides 3 predefined compression levels.
const ( // LevelFastest will choose the least cpu intensive cpu method. LevelFastest Level = iota // LevelBalanced provides balanced compression. // Typical cpu usage will be around 200% of the fastest setting. LevelBalanced // LevelSmallest will use the strongest and most resource intensive // compression method. // This is generally not recommended. LevelSmallest )
type Opts ¶
type Opts uint32
Opts provides options
const ( // OptStatelessGzip will force gzip compression to be stateless. // Since each Write call will compress input this will affect compression ratio // and should only be used when Write calls are controlled. // Typically, this means a buffer should be inserted on the writer. // See https://github.com/klauspost/compress#stateless-compression // Compression level will be ignored. OptStatelessGzip Opts = 1 << iota // OptAllowMultithreadedCompression will allow some compression modes to use multiple goroutines. OptAllowMultithreadedCompression // OptSmallWindow will limit the compression window to 64KB. // This will reduce memory usage of running operations, // but also make compression worse. OptSmallWindow )
Click to show internal directories.
Click to hide internal directories.