github.com/binbinly/pkg@v0.0.11-0.20240321014439-f4fbf666eb0f/signature/generate.go (about)

     1  package signature
     2  
     3  import (
     4  	"encoding/base64"
     5  	"fmt"
     6  	"time"
     7  )
     8  
     9  // Generate η”Ÿζˆη­Ύε
    10  func (s *signature) Generate(params any) (auth string, ts int64, err error) {
    11  	ts = time.Now().Unix()
    12  
    13  	buffer, err := s.data(ts, params)
    14  	if err != nil {
    15  		return "", 0, err
    16  	}
    17  	digest := base64.StdEncoding.EncodeToString(s.cryptoFunc(buffer, []byte(s.secret)))
    18  
    19  	auth = fmt.Sprintf("%s %s", s.key, digest)
    20  	return auth, ts, nil
    21  }