1 Star 0 Fork 97

LoongHealth/teamide

forked from 朱亮/teamide 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 3.30 KB
一键复制 编辑 原始数据 按行查看 历史
朱亮 提交于 2022-05-19 23:52 . 添加新版本检测
package main
import (
"fmt"
"go.uber.org/zap"
"os"
"os/user"
"path/filepath"
"strings"
"sync"
"teamide/internal"
"teamide/internal/context"
"teamide/pkg/util"
"teamide/pkg/window"
)
var (
waitGroupForStop sync.WaitGroup
serverTitle = "Team · IDE"
serverUrl = ""
// buildFlags go build -ldflags '-X main.buildFlags=--isServer' .
buildFlags = ""
version = ""
isServer = false
isHtmlDev = false
isServerDev = false
rootDir string
userHomeDir string
)
func getUserHome() string {
user, err := user.Current()
if nil == err {
return user.HomeDir
}
return ""
}
func init() {
var err error
if strings.Contains(buildFlags, "--isServer") {
isServer = true
}
if strings.Contains(buildFlags, "--isDev") || strings.Contains(buildFlags, "--isHtmlDev") {
isHtmlDev = true
}
if strings.Contains(buildFlags, "--isDev") || strings.Contains(buildFlags, "--isServerDev") {
isServerDev = true
}
rootDir, err = os.Getwd()
if err != nil {
panic(err)
}
rootDir, err = filepath.Abs(rootDir)
if err != nil {
panic(err)
}
rootDir = filepath.ToSlash(rootDir)
if !strings.HasSuffix(rootDir, "/") {
rootDir += "/"
}
userHome := getUserHome()
if userHome != "" {
userHome, err = filepath.Abs(userHome)
if err != nil {
panic(err)
}
userHomeDir = filepath.ToSlash(userHome)
if !strings.HasSuffix(userHomeDir, "/") {
userHomeDir += "/"
}
}
}
func main() {
var err error
var serverContext *context.ServerContext
defer func() {
if err := recover(); err != nil {
fmt.Println("启动失败:", err)
if serverContext != nil {
serverContext.Logger.Error("启动失败", zap.Any("error", err))
}
waitGroupForStop.Done()
}
}()
for _, v := range os.Args {
if v == "--isServer" {
isServer = true
}
if v == "--isDev" || v == "--isHtmlDev" {
isHtmlDev = true
}
if v == "--isDev" || v == "--isServerDev" {
isServerDev = true
}
}
waitGroupForStop.Add(1)
serverConf := &context.ServerConf{
Version: version,
IsServer: isServer,
IsHtmlDev: isHtmlDev,
IsServerDev: isServerDev,
RootDir: rootDir,
UserHomeDir: userHomeDir,
}
err = formatServerConf(serverConf)
if err != nil {
panic(err)
}
serverContext, err = context.NewServerContext(*serverConf)
if err != nil {
panic(err)
}
serverUrl, err = internal.Start(serverContext)
if err != nil {
panic(err)
}
if serverContext.IsHtmlDev {
serverUrl = "http://127.0.0.1:21081/"
}
if !serverContext.IsServer {
err = window.Start(serverUrl, func() {
waitGroupForStop.Done()
})
if err != nil {
panic(err)
}
}
waitGroupForStop.Wait()
}
func formatServerConf(serverConf *context.ServerConf) (err error) {
if serverConf.IsServer {
serverConf.Server = serverConf.RootDir + "conf/sqlite.yaml"
serverConf.PublicKey = serverConf.RootDir + "conf/publicKey.pem"
serverConf.PrivateKey = serverConf.RootDir + "conf/privateKey.pem"
var exists bool
exists, err = util.PathExists(serverConf.Server)
if err != nil {
return
}
if !exists {
serverConf.Server = ""
}
exists, err = util.PathExists(serverConf.PublicKey)
if err != nil {
return
}
if !exists {
serverConf.PublicKey = ""
}
exists, err = util.PathExists(serverConf.PrivateKey)
if err != nil {
return
}
if !exists {
serverConf.PrivateKey = ""
}
}
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/cloud-medical-vidio/teamide.git
[email protected]:cloud-medical-vidio/teamide.git
cloud-medical-vidio
teamide
teamide
main

搜索帮助