Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Commit 0f9a408

Browse files
authored
Merge pull request #43 from KusionStack/more-flexible-placeholder-in-custom-config
feat: support more flexible placeholder writing in archive download url
2 parents 19b49fc + fcd58c3 commit 0f9a408

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ linters:
4343
- unconvert
4444
- unparam
4545
- whitespace
46-
- wsl
46+
# - wsl
4747

4848
linters-settings:
4949
gofumpt:
5050
# Select the Go version to target. The default is `1.15`.
5151
lang-version: "1.17"
5252
# Choose whether or not to use the extra rules that are disabled
5353
# by default
54-
extra-rules: false
54+
extra-rules: false

pkg/sources/custom/types.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package custom
22

33
import (
4+
"bytes"
45
"fmt"
6+
"html/template"
57
"runtime"
68
)
79

@@ -14,11 +16,20 @@ func getArchiveDownloadURL(archiveDownloadURLMap map[string]string, ver string)
1416
if archiveDownloadURLMap == nil {
1517
return "", ErrEmptyDownloadURLMap
1618
}
17-
18-
if urlPattern, ok := archiveDownloadURLMap[getOsArchKey(runtime.GOOS, runtime.GOARCH)]; ok {
19-
return fmt.Sprintf(urlPattern, ver), nil
19+
osArchKey := getOsArchKey(runtime.GOOS, runtime.GOARCH)
20+
if urlPattern, ok := archiveDownloadURLMap[osArchKey]; ok {
21+
tmpl, err := template.New("").Parse(urlPattern)
22+
if err != nil {
23+
return "", err
24+
}
25+
var buf bytes.Buffer
26+
data := struct{ VERSION string }{ver}
27+
if err := tmpl.Execute(&buf, data); err != nil {
28+
return "", err
29+
}
30+
fmt.Println(buf.String())
31+
return buf.String(), nil
2032
}
21-
2233
return "", ErrUnsupportedOsArch
2334
}
2435

pkg/version/types.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ var versionInfo *Info
2121
// Info contains versioning information.
2222
// following attributes:
2323
//
24-
// ReleaseVersion - "vX.Y.Z-00000000" used to indicate the last release version,
25-
// containing GitVersion and GitCommitShort.
26-
// GitVersion - "vX.Y.Z" used to indicate the last git tag.
27-
// GitCommit - The git commit id corresponding to this source code.
28-
// GitTreeState - "clean" indicates no changes since the git commit id
29-
// "dirty" indicates source code changes after the git commit id
24+
// ReleaseVersion - "vX.Y.Z-00000000" used to indicate the last release version,
25+
// containing GitVersion and GitCommitShort.
26+
// GitVersion - "vX.Y.Z" used to indicate the last git tag.
27+
// GitCommit - The git commit id corresponding to this source code.
28+
// GitTreeState - "clean" indicates no changes since the git commit id
29+
// "dirty" indicates source code changes after the git commit id
3030
type Info struct {
3131
ReleaseVersion string `json:"releaseVersion" yaml:"releaseVersion"` // Such as "v1.2.3-3836f877"
3232
GitVersion string `json:"gitVersion" yaml:"gitVersion"` // Such as "v1.2.3"

0 commit comments

Comments
 (0)