dispatcher.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package model
  2. import "net/http"
  3. type Middleware interface {
  4. Handle(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc)
  5. }
  6. type ServerConfig struct {
  7. ServiceName string `json:"service,omitempty" yaml:"service,omitempty"`
  8. BaseURI string `json:"baseUri,omitempty" yaml:"baseUri,omitempty"`
  9. Port int `json:"port,omitempty" yaml:"port,omitempty"`
  10. Commands []JRPCCommand `json:"-" yaml:"-"` // The RPC Commands
  11. Version string `json:"version,omitempty" yaml:"version,omitempty"`
  12. Hostname string `json:"host,omitempty" yaml:"host,omitempty"` // Which host service is bound to - if blank defaults to os.Hostname(), used for consul connection
  13. Consul string `json:"consul,omitempty" yaml:"consul,omitempty"` // where consul host is located. If blank no consul integration made: its host and port
  14. Middleware []func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) `json:"-" yaml:"-"` // A list of handlers to use ... logger security etc
  15. }
  16. /**
  17. Instances allow core access config irrespective of whats in the config
  18. **/
  19. type ServerConfigReader interface {
  20. ReadServerConfig() (*ServerConfig, error)
  21. }
  22. /**
  23. This is the simplest example of a config
  24. **/
  25. type DefaultConfiguration struct {
  26. Server ServerConfig `json:"server,omitempty" yaml:"server,omitempty"`
  27. }
  28. /**
  29. Return Server Config
  30. **/
  31. func (config DefaultConfiguration) ReadServerConfig() (*ServerConfig, error) {
  32. return &config.Server, nil
  33. }