common_service.go 800 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package service
  2. import "fmt"
  3. type Service interface {
  4. Index() string
  5. Sample(username string) string
  6. Admin(username string) string
  7. // HealthCheck check service health status
  8. HealthCheck() bool
  9. }
  10. type CommonService struct {
  11. }
  12. func (s *CommonService) Index() string {
  13. return fmt.Sprintf("hello, wecome to index")
  14. }
  15. func (s *CommonService) Sample(username string) string {
  16. return fmt.Sprintf("hello %s, wecome to sample", username)
  17. }
  18. func (s *CommonService) Admin(username string) string {
  19. return fmt.Sprintf("hello %s, wecome to admin", username)
  20. }
  21. // HealthCheck implement Service method
  22. // 用于检查服务的健康状态,这里仅仅返回true
  23. func (s *CommonService) HealthCheck() bool {
  24. return true
  25. }
  26. func NewCommonService() *CommonService {
  27. return &CommonService{}
  28. }