Skip to content

Commit

Permalink
Merge pull request #43 from KusionStack/more-flexible-placeholder-in-…
Browse files Browse the repository at this point in the history
…custom-config

feat: support more flexible placeholder writing in archive download url
  • Loading branch information
elliotxx committed Aug 3, 2023
2 parents 19b49fc + fcd58c3 commit 0f9a408
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Expand Up @@ -43,12 +43,12 @@ linters:
- unconvert
- unparam
- whitespace
- wsl
# - wsl

linters-settings:
gofumpt:
# Select the Go version to target. The default is `1.15`.
lang-version: "1.17"
# Choose whether or not to use the extra rules that are disabled
# by default
extra-rules: false
extra-rules: false
19 changes: 15 additions & 4 deletions pkg/sources/custom/types.go
@@ -1,7 +1,9 @@
package custom

import (
"bytes"
"fmt"
"html/template"
"runtime"
)

Expand All @@ -14,11 +16,20 @@ func getArchiveDownloadURL(archiveDownloadURLMap map[string]string, ver string)
if archiveDownloadURLMap == nil {
return "", ErrEmptyDownloadURLMap
}

if urlPattern, ok := archiveDownloadURLMap[getOsArchKey(runtime.GOOS, runtime.GOARCH)]; ok {
return fmt.Sprintf(urlPattern, ver), nil
osArchKey := getOsArchKey(runtime.GOOS, runtime.GOARCH)
if urlPattern, ok := archiveDownloadURLMap[osArchKey]; ok {
tmpl, err := template.New("").Parse(urlPattern)
if err != nil {
return "", err
}
var buf bytes.Buffer
data := struct{ VERSION string }{ver}
if err := tmpl.Execute(&buf, data); err != nil {
return "", err
}
fmt.Println(buf.String())
return buf.String(), nil
}

return "", ErrUnsupportedOsArch
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/version/types.go
Expand Up @@ -21,12 +21,12 @@ var versionInfo *Info
// Info contains versioning information.
// following attributes:
//
// ReleaseVersion - "vX.Y.Z-00000000" used to indicate the last release version,
// containing GitVersion and GitCommitShort.
// GitVersion - "vX.Y.Z" used to indicate the last git tag.
// GitCommit - The git commit id corresponding to this source code.
// GitTreeState - "clean" indicates no changes since the git commit id
// "dirty" indicates source code changes after the git commit id
// ReleaseVersion - "vX.Y.Z-00000000" used to indicate the last release version,
// containing GitVersion and GitCommitShort.
// GitVersion - "vX.Y.Z" used to indicate the last git tag.
// GitCommit - The git commit id corresponding to this source code.
// GitTreeState - "clean" indicates no changes since the git commit id
// "dirty" indicates source code changes after the git commit id
type Info struct {
ReleaseVersion string `json:"releaseVersion" yaml:"releaseVersion"` // Such as "v1.2.3-3836f877"
GitVersion string `json:"gitVersion" yaml:"gitVersion"` // Such as "v1.2.3"
Expand Down

0 comments on commit 0f9a408

Please sign in to comment.