server.go 659 B

12345678910111213141516171819202122232425262728293031323334
  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. s := &Server{router: router}
  15. router.GET("/ping", ping)
  16. router.POST("/parse", s.parse)
  17. return s
  18. }
  19. // ping is a dummy function to check if the server is running and responding.
  20. func ping(c *gin.Context) {
  21. c.JSON(http.StatusOK, gin.H{"message": "pong"})
  22. }
  23. // Run runs the server!
  24. func (s *Server) Run() {
  25. s.router.Run()
  26. }