From 48e9899813195c4a8bb978b6c98d1eb22045674c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=AF=E8=88=AA?= <101104760+ZhangSetSail@users.noreply.github.com> Date: Thu, 11 Jan 2024 18:56:10 +0800 Subject: [PATCH] perf: some minor detail fixes during development --- api/api/api_interface.go | 1 + api/controller/cluster.go | 7 ------- api/controller/lg_pack.go | 5 +++++ api/model/model.go | 1 + cmd/version.go | 2 +- db/mysql/dao/lg_pack.go | 4 ++++ db/mysql/mysql.go | 19 +++++++++++++++++++ 7 files changed, 31 insertions(+), 8 deletions(-) diff --git a/api/api/api_interface.go b/api/api/api_interface.go index e5425c0664..0781174119 100644 --- a/api/api/api_interface.go +++ b/api/api/api_interface.go @@ -215,6 +215,7 @@ type AppInterface interface { UploadID(w http.ResponseWriter, r *http.Request) } +// LongVersionInterface long version interface type LongVersionInterface interface { UploadLongVersion(w http.ResponseWriter, r *http.Request) OptionLongVersion(w http.ResponseWriter, r *http.Request) diff --git a/api/controller/cluster.go b/api/controller/cluster.go index cd0b3a6175..a8dd90f706 100644 --- a/api/controller/cluster.go +++ b/api/controller/cluster.go @@ -473,13 +473,6 @@ func (c *ClusterController) GetLangVersion(w http.ResponseWriter, r *http.Reques httputil.ReturnBcodeError(r, w, fmt.Errorf("update lang version failure: %v", err)) return } - //if versions != nil && len(versions) == 0 { - // versions, err = db.GetManager().LongVersionDao().InitLanguageVersion(language) - // if err != nil { - // httputil.ReturnBcodeError(r, w, fmt.Errorf("failed to get language pack version")) - // return - // } - //} httputil.ReturnSuccess(r, w, versions) } diff --git a/api/controller/lg_pack.go b/api/controller/lg_pack.go index 7c36e26323..2af49c7b66 100644 --- a/api/controller/lg_pack.go +++ b/api/controller/lg_pack.go @@ -17,8 +17,10 @@ import ( // LongVersionStruct - type LongVersionStruct struct{} +// BaseUploadPath lang version base dir const BaseUploadPath = "/grdata/lang" +// UploadLongVersion - func (t *LongVersionStruct) UploadLongVersion(w http.ResponseWriter, r *http.Request) { //从表单中读取文件 file, fileHeader, err := r.FormFile("file") @@ -69,6 +71,7 @@ func (t *LongVersionStruct) UploadLongVersion(w http.ResponseWriter, r *http.Req sendResponse(w, http.StatusOK, "successful", long) } +// DownloadLongVersion - func (t *LongVersionStruct) DownloadLongVersion(w http.ResponseWriter, r *http.Request) { language := strings.TrimSpace(chi.URLParam(r, "language")) version := strings.TrimSpace(chi.URLParam(r, "version")) @@ -80,6 +83,7 @@ func (t *LongVersionStruct) DownloadLongVersion(w http.ResponseWriter, r *http.R http.ServeFile(w, r, path.Join(BaseUploadPath, ver.EventID, ver.FileName)) } +// OptionLongVersion - func (t *LongVersionStruct) OptionLongVersion(w http.ResponseWriter, r *http.Request) { origin := r.Header.Get("Origin") w.Header().Add("Access-Control-Allow-Origin", origin) @@ -102,6 +106,7 @@ func generateRandomString(n int) (string, error) { return string(bytes), nil } +// APIResponse = type APIResponse struct { Code int `json:"code"` Message string `json:"message"` diff --git a/api/model/model.go b/api/model/model.go index 95b237faf2..bed8df5e68 100644 --- a/api/model/model.go +++ b/api/model/model.go @@ -2243,6 +2243,7 @@ type UploadChartValueYaml struct { Readme string `json:"readme"` } +// UpdateLangVersion - type UpdateLangVersion struct { Lang string `json:"lang"` Version string `json:"version"` diff --git a/cmd/version.go b/cmd/version.go index f8c2161e4e..bbeeb0b219 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -37,5 +37,5 @@ func ShowVersion(module string) { // GetVersion GetVersion func GetVersion() string { - return "tstt" + return version } diff --git a/db/mysql/dao/lg_pack.go b/db/mysql/dao/lg_pack.go index dc8cda7660..d4920cd793 100644 --- a/db/mysql/dao/lg_pack.go +++ b/db/mysql/dao/lg_pack.go @@ -38,6 +38,7 @@ func (t *LongVersionDaoImpl) ListVersionByLanguage(language string) ([]*model.En return versions, nil } +// GetVersionByLanguageAndVersion - func (t *LongVersionDaoImpl) GetVersionByLanguageAndVersion(language, version string) (*model.EnterpriseLanguageVersion, error) { ver := new(model.EnterpriseLanguageVersion) if err := t.DB.Where("lang = ? and version = ?", language, version).Find(ver).Error; err != nil { @@ -46,6 +47,7 @@ func (t *LongVersionDaoImpl) GetVersionByLanguageAndVersion(language, version st return ver, nil } +// DefaultLangVersion - func (t *LongVersionDaoImpl) DefaultLangVersion(lang string, version string) error { defaultVersion := new(model.EnterpriseLanguageVersion) if err := t.DB.Debug().Where("lang = ? AND first_choice = ?", lang, true).Find(defaultVersion).Error; err != nil { @@ -73,6 +75,7 @@ func (t *LongVersionDaoImpl) DefaultLangVersion(lang string, version string) err return nil } +// CreateLangVersion - func (t *LongVersionDaoImpl) CreateLangVersion(lang, version, eventID, fileName string) error { ver := new(model.EnterpriseLanguageVersion) err := t.DB.Where("lang = ? and version = ?", lang, version).Find(ver).Error @@ -92,6 +95,7 @@ func (t *LongVersionDaoImpl) CreateLangVersion(lang, version, eventID, fileName return err } +// DeleteLangVersion - func (t *LongVersionDaoImpl) DeleteLangVersion(lang, version string) (string, error) { ver := new(model.EnterpriseLanguageVersion) if err := t.DB.Where("lang = ? and version = ?", lang, version).Find(ver).Error; err != nil { diff --git a/db/mysql/mysql.go b/db/mysql/mysql.go index 10ced8a84d..151197c85b 100644 --- a/db/mysql/mysql.go +++ b/db/mysql/mysql.go @@ -297,6 +297,7 @@ func (m *Manager) initLanguageVersion() { } } +// GolangInitVersion - var GolangInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "golang", @@ -354,6 +355,8 @@ var GolangInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "go1.12.17.tar.gz", }, } + +// OpenJDKInitVersion - var OpenJDKInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "openJDK", @@ -418,6 +421,8 @@ var OpenJDKInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "OpenJDK1.8.tar.gz", }, } + +// PythonInitVersion - var PythonInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "python", @@ -457,6 +462,8 @@ var PythonInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "Python2.7.18.tar.gz", }, } + +// MavenInitVersion - var MavenInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "maven", @@ -502,6 +509,8 @@ var MavenInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "Maven3.1.1.tar.gz", }, } + +// PHPInitVersion - var PHPInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "php", @@ -517,6 +526,8 @@ var PHPInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "php8.1.18.tar.gz", }, } + +// NodeInitVersion - var NodeInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "node", @@ -586,6 +597,8 @@ var NodeInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "Node11.15.0.tar.gz", }, } + +// WebCompilerInitVersion - var WebCompilerInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "web_compiler", @@ -625,6 +638,8 @@ var WebCompilerInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "jetty9.tar.gz", }, } + +// WebRuntimeInitVersion - var WebRuntimeInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "web_runtime", @@ -640,6 +655,8 @@ var WebRuntimeInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "apache-2.2.19.tar.gz", }, } + +// NetCompilerInitVersion - var NetCompilerInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "net_compiler", @@ -655,6 +672,8 @@ var NetCompilerInitVersion = []*model.EnterpriseLanguageVersion{ FileName: "mcr.microsoft.com/dotnet/sdk:2.1-sdk-alpine", }, } + +// NetRuntimeInitVersion - var NetRuntimeInitVersion = []*model.EnterpriseLanguageVersion{ { Lang: "net_runtime",