Zstd compress

Go ztds encoding with marshal

This repository makes it possible to implement data compression without transformations on the side of the application code. Excellent tool for integration with different data transfer protocols

References

  • Zstd realtime compress algorithm - zstd

Installation

1
go get github.com/akhmaos/zstd-marshal

Example

1
2
3
4
5
6
import zstdM "zstd-marshal"

type SomeStruct struct {
Field string `json:"Field"`
SecondField string `json:"SecondField"`
}

We create some struct and set json tag for each because for parse struct we use json marshaling

Decode and encode without concurrency

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
func EncodeAndDecode() {
someData := SomeStruct{
"Test",
"Test2",
}

encodedDataBytes, err := zstdM.Marshal(someData)

if err != nil {
return
}

var stForDecode SomeStruct

err = zstdM.Unmarshal(encodedDataBytes, &stForDecode)
if err != nil {
return
}

Decode and encode with concurrency

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
func EncodeAndDecodeWithConcurrency() {
someData := SomeStruct{
"Test",
"Test2",
}

encodedDataBytes, err := zstdM.MarshalWithConcurrency(someData, runtime.GOMAXPROCS(-1))

if err != nil {
return
}

var stForDecode SomeStruct

err = zstdM.UnmarshalWithConcurrency(encodedDataBytes, &stForDecode, runtime.GOMAXPROCS(-1))
if err != nil {
return
}
}

Recaptcha

Go fiber recaptcha middleware

Install

1
go get github.com/akhmaos/go-fiber-recaptcha

Example

Set config

1
2
3
4
5
6
7
8
9
10
11
12
13
14

type Config struct {
ReCaptcha recaptcha.Config
}

func GetConfig() *Config {

conf := &Config{}

apiKey := os.Getenv("RECAPTCHA_API_KEY)
conf.ReCaptcha.ApiKey = apiKey
return conf
}

Fiber use case as middleware

1
2
3
4

conf := GetConfig()
app := fiber.New()
app.Use(recaptcha.New(conf.ReCaptcha))

Set Custom header

1
2
3
4
5
6
7
8
9
10
func GetConfig() *Config {

conf := &Config{}

apiKey := os.Getenv("RECAPTCHA_API_KEY)
conf.ReCaptcha.ApiKey = apiKey

conf.ReCaptcha.ReTokenHeader = "Custom-Header"
return conf
}

Set Custom Scope

1
2
3
4
5
6
7
8
9
10
func GetConfig() *Config {

conf := &Config{}

apiKey := os.Getenv("RECAPTCHA_API_KEY)
conf.ReCaptcha.ApiKey = apiKey

conf.ReCaptcha.Scope = 0.8
return conf
}

Set Custom Verify URL

1
2
3
4
5
6
7
8
9
10
func GetConfig() *Config {

conf := &Config{}

apiKey := os.Getenv("RECAPTCHA_API_KEY)
conf.ReCaptcha.ApiKey = apiKey

conf.ReCaptcha.VerifyUrl = "https://example.com/"
return conf
}
dark
sans