server.go 616 B

123456789101112131415161718192021222324252627282930313233
  1. package web
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // Server is the exposed struct that contains necessary configuration and setup
  7. // to run the web server.
  8. type Server struct {
  9. router *gin.Engine
  10. }
  11. // NewServer returns a configured instance of the web server.
  12. func NewServer() *Server {
  13. router := gin.Default()
  14. router.GET("/ping", ping)
  15. return &Server{
  16. router: router,
  17. }
  18. }
  19. // ping is a dummy function to see if things are running well enough.
  20. func ping(c *gin.Context) {
  21. c.JSON(http.StatusOK, gin.H{"message": "pong"})
  22. }
  23. // Run runs our server!
  24. func (s *Server) Run() {
  25. s.router.Run()
  26. }