vpoint.go 734 B

1234567891011121314151617181920212223242526272829303132
  1. package core
  2. import (
  3. "fmt"
  4. )
  5. type VPoint struct {
  6. config VConfig
  7. connHandler ConnectionHandler
  8. }
  9. // NewVPoint returns a new VPoint server based on given configuration.
  10. // The server is not started at this point.
  11. func NewVPoint(config *VConfig) (*VPoint, error) {
  12. var vpoint = new(VPoint)
  13. vpoint.config = *config
  14. return vpoint, nil
  15. }
  16. type ConnectionHandler interface {
  17. Listen(port uint16) error
  18. }
  19. // Start starts the VPoint server, and return any error during the process.
  20. // In the case of any errors, the state of the server is unpredicatable.
  21. func (vp *VPoint) Start() error {
  22. if vp.config.Port <= 0 {
  23. return fmt.Errorf("Invalid port %d", vp.config.Port)
  24. }
  25. vp.connHandler.Listen(vp.config.Port)
  26. return nil
  27. }