Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
00a827c2
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
00a827c2
编写于
8月 17, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
U: command-line tool, http request api
上级
93612a21
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
45 addition
and
20 deletion
+45
-20
cmd/energy/energy.go
cmd/energy/energy.go
+3
-0
cmd/internal/create.go
cmd/internal/create.go
+17
-0
cmd/internal/install.go
cmd/internal/install.go
+4
-18
cmd/internal/tools.go
cmd/internal/tools.go
+20
-1
cmd/internal/version.go
cmd/internal/version.go
+1
-1
未找到文件。
cmd/energy/energy.go
浏览文件 @
00a827c2
...
...
@@ -24,6 +24,7 @@ var commands = []*internal.Command{
internal
.
CmdVersion
,
internal
.
CmdSetenv
,
internal
.
CmdEnv
,
internal
.
CmdCreate
,
}
func
main
()
{
...
...
@@ -49,6 +50,8 @@ func main() {
cc
.
Index
=
4
case
"env"
:
cc
.
Index
=
5
case
"create"
:
cc
.
Index
=
6
}
command
:=
commands
[
cc
.
Index
]
if
len
(
extraArgs
)
<
1
||
extraArgs
[
len
(
extraArgs
)
-
1
]
!=
"."
{
...
...
cmd/internal/create.go
浏览文件 @
00a827c2
...
...
@@ -11,3 +11,20 @@
// 创建 energy 项目
package
internal
var
CmdCreate
=
&
Command
{
UsageLine
:
"create"
,
Short
:
"create energy project"
,
Long
:
`
Initialize and create an energy golang project
. Execute default command
`
,
}
func
init
()
{
CmdCreate
.
Run
=
runCreate
}
func
runCreate
(
c
*
CommandConfig
)
error
{
return
nil
}
cmd/internal/install.go
浏览文件 @
00a827c2
...
...
@@ -20,7 +20,6 @@ import (
progressbar
"github.com/energye/energy/v2/cmd/internal/progress-bar"
"io"
"io/fs"
"io/ioutil"
"net/http"
"net/url"
"os"
...
...
@@ -107,7 +106,7 @@ Your current installation environment is Linux and there are two GTK solutions a
os
.
MkdirAll
(
installPathName
,
fs
.
ModePerm
)
os
.
MkdirAll
(
filepath
.
Join
(
c
.
Install
.
Path
,
frameworkCache
),
fs
.
ModePerm
)
println
(
"Start downloading CEF and Energy dependency"
)
downloadJSON
,
err
:=
downloadConfig
(
DownloadVersionURL
)
downloadJSON
,
err
:=
httpRequestGET
(
DownloadVersionURL
)
if
err
!=
nil
{
fmt
.
Fprint
(
os
.
Stderr
,
err
.
Error
()
+
"
\n
"
)
os
.
Exit
(
1
)
...
...
@@ -171,11 +170,13 @@ Your current installation environment is Linux and there are two GTK solutions a
downloadEnergyURL
=
strings
.
ReplaceAll
(
downloadEnergyURL
,
"{OSARCH}"
,
libEnergyOS
)
//提取文件配置
extractData
,
err
:=
downloadConfig
(
DownloadExtractURL
)
extractData
,
err
:=
httpRequestGET
(
DownloadExtractURL
)
if
err
!=
nil
{
fmt
.
Fprint
(
os
.
Stderr
,
err
.
Error
(),
"
\n
"
)
os
.
Exit
(
1
)
}
// 获取安装环境信息
var
extractConfig
map
[
string
]
interface
{}
extractData
=
bytes
.
TrimPrefix
(
extractData
,
[]
byte
(
"
\xef\xbb\xbf
"
))
if
err
:=
json
.
Unmarshal
(
extractData
,
&
extractConfig
);
err
!=
nil
{
...
...
@@ -484,21 +485,6 @@ func urlName(downloadUrl string) string {
}
}
// 下载文件配置
func
downloadConfig
(
url
string
)
([]
byte
,
error
)
{
client
:=
new
(
http
.
Client
)
resp
,
err
:=
client
.
Get
(
url
)
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
ret
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
nil
,
err
}
return
ret
,
nil
}
func
isFileExist
(
filename
string
,
filesize
int64
)
bool
{
info
,
err
:=
os
.
Stat
(
filename
)
if
os
.
IsNotExist
(
err
)
{
...
...
cmd/internal/tools.go
浏览文件 @
00a827c2
...
...
@@ -10,7 +10,11 @@
package
internal
import
"os"
import
(
"io/ioutil"
"net/http"
"os"
)
func
ToString
(
v
interface
{})
string
{
if
v
==
nil
{
...
...
@@ -38,3 +42,18 @@ func IsExist(path string) bool {
}
return
true
}
// http 请求
func
httpRequestGET
(
url
string
)
([]
byte
,
error
)
{
client
:=
new
(
http
.
Client
)
resp
,
err
:=
client
.
Get
(
url
)
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
ret
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
nil
,
err
}
return
ret
,
nil
}
cmd/internal/version.go
浏览文件 @
00a827c2
...
...
@@ -32,7 +32,7 @@ func init() {
}
func
runVersion
(
c
*
CommandConfig
)
error
{
downloadJSON
,
err
:=
downloadConfig
(
DownloadVersionURL
)
downloadJSON
,
err
:=
httpRequestGET
(
DownloadVersionURL
)
if
err
!=
nil
{
fmt
.
Fprint
(
os
.
Stderr
,
err
.
Error
()
+
"
\n
"
)
os
.
Exit
(
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录