server_info.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package data
  2. import (
  3. "fmt"
  4. //"io"
  5. "time"
  6. "github.com/ClickHouse/clickhouse-go/lib/binary"
  7. "github.com/ClickHouse/clickhouse-go/lib/protocol"
  8. )
  9. type ServerInfo struct {
  10. Name string
  11. Revision uint64
  12. MinorVersion uint64
  13. MajorVersion uint64
  14. Timezone *time.Location
  15. }
  16. func (srv *ServerInfo) Read(decoder *binary.Decoder) (err error) {
  17. if srv.Name, err = decoder.String(); err != nil {
  18. return fmt.Errorf("could not read server name: %v", err)
  19. }
  20. if srv.MajorVersion, err = decoder.Uvarint(); err != nil {
  21. return fmt.Errorf("could not read server major version: %v", err)
  22. }
  23. if srv.MinorVersion, err = decoder.Uvarint(); err != nil {
  24. return fmt.Errorf("could not read server minor version: %v", err)
  25. }
  26. if srv.Revision, err = decoder.Uvarint(); err != nil {
  27. return fmt.Errorf("could not read server revision: %v", err)
  28. }
  29. if srv.Revision >= protocol.DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE {
  30. timezone, err := decoder.String()
  31. if err != nil {
  32. return fmt.Errorf("could not read server timezone: %v", err)
  33. }
  34. if srv.Timezone, err = time.LoadLocation(timezone); err != nil {
  35. return fmt.Errorf("could not load time location: %v", err)
  36. }
  37. }
  38. return nil
  39. }
  40. func (srv ServerInfo) String() string {
  41. return fmt.Sprintf("%s %d.%d.%d (%s)", srv.Name, srv.MajorVersion, srv.MinorVersion, srv.Revision, srv.Timezone)
  42. }