diff --git a/internal/manager.go b/internal/manager.go index 52efddce..ab7e1e84 100644 --- a/internal/manager.go +++ b/internal/manager.go @@ -48,8 +48,6 @@ type Manager struct { openSdks map[string]*Sdk EnvManager env.Manager Record env.Record - osType util.OSType - archType util.ArchType Config *config.Config } @@ -472,8 +470,6 @@ func newSdkManager(record env.Record, meta *PathMeta) *Manager { EnvManager: envManger, Record: record, openSdks: make(map[string]*Sdk), - osType: util.GetOSType(), - archType: util.GetArchType(), Config: c, } return manager diff --git a/internal/plugin.go b/internal/plugin.go index 3214c66b..896899b5 100644 --- a/internal/plugin.go +++ b/internal/plugin.go @@ -337,8 +337,8 @@ func NewLuaPlugin(content, path string, manager *Manager) (*LuaPlugin, error) { // !!!! Must be set after loading the script to prevent overwriting! // set OS_TYPE and ARCH_TYPE - vm.Instance.SetGlobal(OsType, lua.LString(manager.osType)) - vm.Instance.SetGlobal(ArchType, lua.LString(manager.archType)) + vm.Instance.SetGlobal(OsType, lua.LString(util.GetOSType())) + vm.Instance.SetGlobal(ArchType, lua.LString(util.GetArchType())) pluginObj := vm.Instance.GetGlobal(LuaPluginObjKey) if pluginObj.Type() == lua.LTNil { diff --git a/internal/util/os.go b/internal/util/os.go deleted file mode 100644 index 191a812d..00000000 --- a/internal/util/os.go +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2024 Han Li and contributors - * - * 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 util - -import "runtime" - -type OSType string - -const ( - MacOS OSType = "darwin" - Windows OSType = "windows" - Linux OSType = "linux" -) - -func GetOSType() OSType { - switch runtime.GOOS { - case "darwin": - return MacOS - case "windows": - return Windows - case "linux": - return Linux - default: - return OSType(runtime.GOOS) - } -} diff --git a/internal/util/arch.go b/internal/util/runtime.go similarity index 76% rename from internal/util/arch.go rename to internal/util/runtime.go index f88d2250..11c686aa 100644 --- a/internal/util/arch.go +++ b/internal/util/runtime.go @@ -18,20 +18,15 @@ package util import "runtime" -type ArchType string - -const ( - AMD64 ArchType = "amd64" - ARM64 ArchType = "arm64" +type ( + OSType string + ArchType string ) +func GetOSType() OSType { + return OSType(runtime.GOOS) +} + func GetArchType() ArchType { - switch runtime.GOARCH { - case "amd64": - return AMD64 - case "arm64": - return ARM64 - default: - return ArchType(runtime.GOARCH) - } + return ArchType(runtime.GOARCH) }