Compare commits

...

4 Commits

Author SHA1 Message Date
65109a787c feat: use GetVersion() 2026-01-26 22:17:14 +01:00
75f1406edf feat: use a getter 2026-01-26 22:17:02 +01:00
11dc9b507f feat: bump version to 0.1.1 2026-01-19 21:07:39 +01:00
da616438e9 chore: update version in swagger 2026-01-19 21:07:30 +01:00
7 changed files with 24 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
// @title Goyco API // @title Goyco API
// @version 0.1.0 // @version 0.1.1
// @description Goyco is a Y Combinator-style news aggregation platform API. // @description Goyco is a Y Combinator-style news aggregation platform API.
// @contact.name Goyco Team // @contact.name Goyco Team
// @contact.email sandro@cazzaniga.fr // @contact.email sandro@cazzaniga.fr
@@ -55,7 +55,7 @@ func run(args []string) error {
docs.SwaggerInfo.Title = fmt.Sprintf("%s API", cfg.App.Title) docs.SwaggerInfo.Title = fmt.Sprintf("%s API", cfg.App.Title)
docs.SwaggerInfo.Description = "Y Combinator-style news board API." docs.SwaggerInfo.Description = "Y Combinator-style news board API."
docs.SwaggerInfo.Version = version.Version docs.SwaggerInfo.Version = version.GetVersion()
docs.SwaggerInfo.BasePath = "/api" docs.SwaggerInfo.BasePath = "/api"
docs.SwaggerInfo.Host = fmt.Sprintf("%s:%s", cfg.Server.Host, cfg.Server.Port) docs.SwaggerInfo.Host = fmt.Sprintf("%s:%s", cfg.Server.Host, cfg.Server.Port)
docs.SwaggerInfo.Schemes = []string{"http"} docs.SwaggerInfo.Schemes = []string{"http"}

View File

@@ -2129,7 +2129,7 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "0.1.0", Version: "0.1.1",
Host: "localhost:8080", Host: "localhost:8080",
BasePath: "/api", BasePath: "/api",
Schemes: []string{"http"}, Schemes: []string{"http"},

View File

@@ -14,7 +14,7 @@
"name": "GPLv3", "name": "GPLv3",
"url": "https://www.gnu.org/licenses/gpl-3.0.html" "url": "https://www.gnu.org/licenses/gpl-3.0.html"
}, },
"version": "0.1.0" "version": "0.1.1"
}, },
"host": "localhost:8080", "host": "localhost:8080",
"basePath": "/api", "basePath": "/api",

View File

@@ -221,7 +221,7 @@ info:
name: GPLv3 name: GPLv3
url: https://www.gnu.org/licenses/gpl-3.0.html url: https://www.gnu.org/licenses/gpl-3.0.html
title: Goyco API title: Goyco API
version: 0.1.0 version: 0.1.1
paths: paths:
/api: /api:
get: get:

View File

@@ -75,7 +75,7 @@ func (h *APIHandler) GetAPIInfo(w http.ResponseWriter, r *http.Request) {
apiInfo := map[string]any{ apiInfo := map[string]any{
"name": fmt.Sprintf("%s API", h.config.App.Title), "name": fmt.Sprintf("%s API", h.config.App.Title),
"version": version.Version, "version": version.GetVersion(),
"description": "Y Combinator-style news board API", "description": "Y Combinator-style news board API",
"endpoints": map[string]any{ "endpoints": map[string]any{
"authentication": map[string]any{ "authentication": map[string]any{
@@ -145,7 +145,7 @@ func (h *APIHandler) GetHealth(w http.ResponseWriter, r *http.Request) {
if h.healthChecker != nil { if h.healthChecker != nil {
health := h.healthChecker.CheckHealth() health := h.healthChecker.CheckHealth()
health["version"] = version.Version health["version"] = version.GetVersion()
SendSuccessResponse(w, "Health check successful", health) SendSuccessResponse(w, "Health check successful", health)
return return
} }
@@ -155,7 +155,7 @@ func (h *APIHandler) GetHealth(w http.ResponseWriter, r *http.Request) {
health := map[string]any{ health := map[string]any{
"status": "healthy", "status": "healthy",
"timestamp": currentTimestamp, "timestamp": currentTimestamp,
"version": version.Version, "version": version.GetVersion(),
"services": map[string]any{ "services": map[string]any{
"database": "connected", "database": "connected",
"api": "running", "api": "running",
@@ -230,7 +230,7 @@ func (h *APIHandler) GetMetrics(w http.ResponseWriter, r *http.Request) {
}, },
"system": map[string]any{ "system": map[string]any{
"timestamp": time.Now().UTC().Format(time.RFC3339), "timestamp": time.Now().UTC().Format(time.RFC3339),
"version": version.Version, "version": version.GetVersion(),
}, },
} }

View File

@@ -1,3 +1,7 @@
package version package version
const Version = "0.1.0" const version = "0.1.1"
func GetVersion() string {
return version
}

View File

@@ -8,39 +8,39 @@ import (
func TestVersionSemver(t *testing.T) { func TestVersionSemver(t *testing.T) {
semverRegex := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`) semverRegex := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
if !semverRegex.MatchString(Version) { if !semverRegex.MatchString(GetVersion()) {
t.Errorf("Version %q does not follow semantic versioning format (MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD])", Version) t.Errorf("Version %q does not follow semantic versioning format (MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD])", GetVersion())
} }
} }
func TestVersionSemverFlexible(t *testing.T) { func TestVersionSemverFlexible(t *testing.T) {
flexibleSemverRegex := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`) flexibleSemverRegex := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
if !flexibleSemverRegex.MatchString(Version) { if !flexibleSemverRegex.MatchString(GetVersion()) {
t.Errorf("Version %q does not follow semantic versioning format (MAJOR.MINOR[.PATCH][-PRERELEASE][+BUILD])", Version) t.Errorf("Version %q does not follow semantic versioning format (MAJOR.MINOR[.PATCH][-PRERELEASE][+BUILD])", GetVersion())
} }
} }
func TestVersionNotEmpty(t *testing.T) { func TestVersionNotEmpty(t *testing.T) {
if Version == "" { if GetVersion() == "" {
t.Error("Version should not be empty") t.Error("Version should not be empty")
} }
} }
func TestVersionFormat(t *testing.T) { func TestVersionFormat(t *testing.T) {
if !regexp.MustCompile(`\d+\.\d+`).MatchString(Version) { if !regexp.MustCompile(`\d+\.\d+`).MatchString(GetVersion()) {
t.Errorf("Version %q should contain at least MAJOR.MINOR format", Version) t.Errorf("Version %q should contain at least MAJOR.MINOR format", GetVersion())
} }
} }
func TestVersionStartsWithNumber(t *testing.T) { func TestVersionStartsWithNumber(t *testing.T) {
if !regexp.MustCompile(`^\d+`).MatchString(Version) { if !regexp.MustCompile(`^\d+`).MatchString(GetVersion()) {
t.Errorf("Version %q should start with a number", Version) t.Errorf("Version %q should start with a number", GetVersion())
} }
} }
func TestVersionNoLeadingZeros(t *testing.T) { func TestVersionNoLeadingZeros(t *testing.T) {
parts := regexp.MustCompile(`^(\d+)\.(\d+)`).FindStringSubmatch(Version) parts := regexp.MustCompile(`^(\d+)\.(\d+)`).FindStringSubmatch(GetVersion())
if len(parts) >= 3 { if len(parts) >= 3 {
major := parts[1] major := parts[1]
minor := parts[2] minor := parts[2]