Initial commit
This commit is contained in:
45
internal/api/version/handler.go
Normal file
45
internal/api/version/handler.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"go.uber.org/fx"
|
||||
|
||||
// import embedded version
|
||||
"payouts/internal/version"
|
||||
)
|
||||
|
||||
// Route version route
|
||||
const Route = "/version"
|
||||
|
||||
// Module is a fx module
|
||||
var Module = fx.Options(
|
||||
fx.Provide(New),
|
||||
)
|
||||
|
||||
// New constructs a new config Handler.
|
||||
func New() (Handler, error) {
|
||||
|
||||
return &handler{
|
||||
version.Version,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Handler config handler interface
|
||||
type Handler interface {
|
||||
VersionHandler(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
type handler struct {
|
||||
version string
|
||||
}
|
||||
|
||||
// VersionHandler handles the version requests
|
||||
func (h *handler) VersionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
io.WriteString(w, h.version)
|
||||
}
|
||||
Reference in New Issue
Block a user