Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-orusapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
go-orusapi
Commits
a24a188961ce
Commit
a24a188961ce
authored
3 years ago
by
Florent Aide
Browse files
Options
Downloads
Patches
Plain Diff
add template for restapi/version.go, injection thx to christophe de vienne
parent
6634e1f0eaac
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
server.yaml
+4
-0
4 additions, 0 deletions
server.yaml
templates/server/cmd.gotmpl
+1
-1
1 addition, 1 deletion
templates/server/cmd.gotmpl
templates/server/versionapi.gotmpl
+31
-0
31 additions, 0 deletions
templates/server/versionapi.gotmpl
version.go
+44
-0
44 additions, 0 deletions
version.go
with
80 additions
and
1 deletion
server.yaml
+
4
−
0
View file @
a24a1889
...
...
@@ -72,6 +72,10 @@
target
:
"
{{
joinFilePath
.Target
.ServerPackage
}}"
file_name
:
"
configure_{{
.Name
}}.go"
skip_exists
:
true
-
name
:
version
source
:
server/versionapi.gotmpl
target
:
"
{{
joinFilePath
.Target
.ServerPackage
}}"
file_name
:
version.go
models
:
# built-in templates
...
...
This diff is collapsed.
Click to expand it.
templates/server/cmd.gotmpl
+
1
−
1
View file @
a24a1889
...
...
@@ -9,7 +9,7 @@
)
var (
Version
string
Version
= restapi.GetVersion()
)
type ConfigFile struct {
...
...
This diff is collapsed.
Click to expand it.
templates/server/versionapi.gotmpl
0 → 100644
+
31
−
0
View file @
a24a1889
// This file is safe to edit. Once it exists it will not be overwritten
{{ if .Copyright -}}// {{ comment .Copyright -}}{{ end }}
package {{ .APIPackage }}
import (
"encoding/json"
{{ imports .DefaultImports }}
{{ imports .Imports }}
)
var (
VCSCommit string
VersionTag = "dev"
injectVersion = orusapi.InjectVersion(VersionTag, VCSCommit)
)
func GetSwaggerJSON() json.RawMessage {
return injectVersion(SwaggerJSON)
}
func GetFlatSwaggerJSON() json.RawMessage {
return injectVersion(FlatSwaggerJSON)
}
func GetVersion() string {
return orusapi.GetVersion(GetSwaggerJSON())
}
This diff is collapsed.
Click to expand it.
version.go
0 → 100644
+
44
−
0
View file @
a24a1889
package
orusapi
import
(
"encoding/json"
"regexp"
)
var
versionAttrRe
=
regexp
.
MustCompile
(
`"version": ?"[0-9.]+"`
)
func
JSONFixVersionAttribute
(
versionTag
,
vcsCommit
string
)
func
(
data
[]
byte
)
[]
byte
{
return
func
(
data
[]
byte
)
[]
byte
{
if
versionTag
==
""
{
return
data
}
s
:=
string
(
data
[
:
len
(
data
)
-
1
])
+
"-"
+
versionTag
if
vcsCommit
!=
""
{
s
+=
"."
+
vcsCommit
}
s
+=
`"`
return
[]
byte
(
s
)
}
}
func
InjectVersion
(
versionTag
,
vcsCommit
string
)
func
(
json
.
RawMessage
)
json
.
RawMessage
{
jsonFixVersionAttribute
:=
JSONFixVersionAttribute
(
versionTag
,
vcsCommit
)
return
func
(
swaggerJSON
json
.
RawMessage
)
json
.
RawMessage
{
return
versionAttrRe
.
ReplaceAllFunc
(
swaggerJSON
,
jsonFixVersionAttribute
)
}
}
type
swaggerVersion
struct
{
Info
struct
{
Version
string
}
}
func
GetVersion
(
swaggerJSON
json
.
RawMessage
)
string
{
var
sv
swaggerVersion
if
err
:=
json
.
Unmarshal
(
swaggerJSON
,
&
sv
);
err
!=
nil
{
panic
(
err
)
}
return
sv
.
Info
.
Version
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment