refactor: remove utils pkg

BREAKING CHANGE: utils package has been removed in favor of specific new
packages (http, crypto, strings)
This commit is contained in:
Livio Amstutz 2021-09-27 11:58:28 +02:00
parent 251c476e17
commit 0ab5ea5a57
40 changed files with 131 additions and 126 deletions

27
pkg/crypto/sign.go Normal file
View file

@ -0,0 +1,27 @@
package crypto
import (
"encoding/json"
"errors"
"gopkg.in/square/go-jose.v2"
)
func Sign(object interface{}, signer jose.Signer) (string, error) {
payload, err := json.Marshal(object)
if err != nil {
return "", err
}
return SignPayload(payload, signer)
}
func SignPayload(payload []byte, signer jose.Signer) (string, error) {
if signer == nil {
return "", errors.New("missing signer")
}
result, err := signer.Sign(payload)
if err != nil {
return "", err
}
return result.CompactSerialize()
}