http.go 797 B

1234567891011121314151617181920212223242526272829303132333435
  1. package conf
  2. import (
  3. "github.com/golang/protobuf/proto"
  4. "v2ray.com/core/proxy/http"
  5. )
  6. type HttpAccount struct {
  7. Username string `json:"user"`
  8. Password string `json:"pass"`
  9. }
  10. type HttpServerConfig struct {
  11. Timeout uint32 `json:"timeout"`
  12. Accounts []*HttpAccount `json:"accounts"`
  13. Transparent bool `json:"allowTransparent"`
  14. UserLevel uint32 `json:"userLevel"`
  15. }
  16. func (c *HttpServerConfig) Build() (proto.Message, error) {
  17. config := &http.ServerConfig{
  18. Timeout: c.Timeout,
  19. AllowTransparent: c.Transparent,
  20. UserLevel: c.UserLevel,
  21. }
  22. if len(c.Accounts) > 0 {
  23. config.Accounts = make(map[string]string)
  24. for _, account := range c.Accounts {
  25. config.Accounts[account.Username] = account.Password
  26. }
  27. }
  28. return config, nil
  29. }