/
zhendosina
/
obshell
Обзор
Документация
Войти
/
zhendosina
/
obshell
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
ob/agent/executor/obproxy/utils.go
54 строки
1 KB
Junkrat77
PullRequest: 654 fix: obproxy management
28 ноя 2025, 13:05
28 ноя 2025, 13:05
b90fc8f
Код
Авторство
О чём код?
/* * Copyright (c) 2024 OceanBase. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package obproxy import ( "os" "os/exec" "regexp" "strings" "github.com/oceanbase/obshell/ob/agent/errors" ) func getObproxyVersion(homepath string) (string, error) { originalDir, _ := os.Getwd() defer func() { if originalDir != "" { os.Chdir(originalDir) } }() if err := os.Chdir(homepath); err != nil { return "", err } output, err := exec.Command("./bin/obproxy", "-V").CombinedOutput() if err != nil { return "", err } re := regexp.MustCompile(`\(OceanBase (\d+\.\d+\.\d+\.\d+) (\d+(?:\.[\w]+)?)\)`) matches := re.FindStringSubmatch(string(output)) if len(matches) < 3 { return "", errors.Occur(errors.ErrOBProxyVersionOutputUnexpected, string(output)) } version := matches[1] buildNum := matches[2] // Remove suffix like .el7 from build number if idx := strings.Index(buildNum, "."); idx != -1 { buildNum = buildNum[:idx] } return strings.Join([]string{version, buildNum}, "-"), nil }