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.

serve.go 1.2 kB

10 months ago
2 years ago
10 months ago
10 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package cmdline
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/cloudream/storage/client/internal/config"
  5. "gitlink.org.cn/cloudream/storage/client/internal/http"
  6. )
  7. // ServeHTTP 启动HTTP服务。
  8. // ctx: 命令行上下文,包含服务配置等信息。
  9. // args: 命令行参数,第一个参数可选地指定HTTP服务器监听地址。
  10. // 返回值: 如果启动过程中遇到错误,返回错误信息;否则返回nil。
  11. func ServeHTTP(ctx CommandContext, args []string) error {
  12. // 默认监听地址为":7890",如果提供了命令行参数,则使用参数指定的地址。
  13. listenAddr := ":7890"
  14. if len(args) > 0 {
  15. listenAddr = args[0]
  16. }
  17. awsAuth, err := http.NewAWSAuth(config.Cfg().AuthAccessKey, config.Cfg().AuthSecretKey)
  18. if err != nil {
  19. return fmt.Errorf("new aws auth: %w", err)
  20. }
  21. // 创建一个新的HTTP服务器实例。
  22. httpSvr, err := http.NewServer(listenAddr, ctx.Cmdline.Svc, awsAuth)
  23. if err != nil {
  24. return fmt.Errorf("new http server: %w", err)
  25. }
  26. // 启动HTTP服务。
  27. err = httpSvr.Serve()
  28. if err != nil {
  29. return fmt.Errorf("serving http: %w", err)
  30. }
  31. return nil
  32. }
  33. // 初始化函数,将ServeHTTP命令注册到命令列表中。
  34. func init() {
  35. commands.MustAdd(ServeHTTP, "serve", "http")
  36. }

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