You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.go 888 B

7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package api
  2. import (
  3. "crypto/tls"
  4. "crypto/x509"
  5. "fmt"
  6. "os"
  7. )
  8. type ConfigJSON struct {
  9. EndPoint string `json:"endpoint"`
  10. RootCA string `json:"rootCA"`
  11. ClientCert string `json:"clientCert"`
  12. ClientKey string `json:"clientKey"`
  13. }
  14. func (c *ConfigJSON) Build() (Config, error) {
  15. rootCAPool := x509.NewCertPool()
  16. rootCAPem, err := os.ReadFile(c.RootCA)
  17. if err != nil {
  18. return Config{}, fmt.Errorf("reading root CA: %w", err)
  19. }
  20. if !rootCAPool.AppendCertsFromPEM(rootCAPem) {
  21. return Config{}, fmt.Errorf("parsing root CA failed")
  22. }
  23. cliCert, err := tls.LoadX509KeyPair(c.ClientCert, c.ClientKey)
  24. if err != nil {
  25. return Config{}, fmt.Errorf("loading client cert: %w", err)
  26. }
  27. return Config{
  28. EndPoint: c.EndPoint,
  29. RootCA: rootCAPool,
  30. Cert: cliCert,
  31. }, nil
  32. }
  33. type Config struct {
  34. EndPoint string
  35. RootCA *x509.CertPool
  36. Cert tls.Certificate
  37. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。