代码拉取完成,页面将自动刷新
package api
import (
"encoding/base64"
"fmt"
"io/ioutil"
"sync"
)
const numSecretBytes = 32
type Secret struct {
Path string
bytes []byte
sync.RWMutex
}
// Lazy access to the HMAC secret key. We must be lazy because if the key
// is not already there, it will be generated by gitlab-rails, and
// gitlab-rails is slow.
func (s *Secret) Bytes() ([]byte, error) {
if bytes := s.getBytes(); bytes != nil {
return bytes, nil
}
return s.setBytes()
}
func (s *Secret) getBytes() []byte {
s.RLock()
defer s.RUnlock()
return s.bytes
}
func (s *Secret) setBytes() ([]byte, error) {
s.Lock()
defer s.Unlock()
if s.bytes != nil {
return s.bytes, nil
}
base64Bytes, err := ioutil.ReadFile(s.Path)
if err != nil {
return nil, fmt.Errorf("read Secret.Path: %v", err)
}
secretBytes := make([]byte, base64.StdEncoding.DecodedLen(len(base64Bytes)))
n, err := base64.StdEncoding.Decode(secretBytes, base64Bytes)
if err != nil {
return nil, fmt.Errorf("decode secret: %v", err)
}
if n != numSecretBytes {
return nil, fmt.Errorf("expected %d secretBytes in %s, found %d", numSecretBytes, s.Path, n)
}
s.bytes = secretBytes
return s.bytes, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。