Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cangjie1.0.1-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eazy-template
cangjie1.0.1-template
Commits
528b1483
Commit
528b1483
authored
Sep 11, 2025
by
xiezhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
a0612ce7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
22 deletions
+28
-22
Dockerfile
Dockerfile
+2
-2
Makefile
Makefile
+2
-2
README.md
README.md
+10
-10
cjpm.toml
cjpm.toml
+8
-2
docker-entrypoint.sh
docker-entrypoint.sh
+2
-2
helloworld.cj
src/helloworld.cj
+4
-4
No files found.
Dockerfile
View file @
528b1483
# 使用仓颉1.0.1作为基础镜像
# 使用仓颉1.0.1作为基础镜像
FROM
hb.eazytec-cloud.com/eazytec/eazydevelop-cangjie:ubuntu2
0
.04-cangjie1.0.1-latest
FROM
hb.eazytec-cloud.com/eazytec/eazydevelop-cangjie:ubuntu2
2
.04-cangjie1.0.1-latest
# 设置工作目录
# 设置工作目录
WORKDIR
/app
WORKDIR
/app
...
@@ -18,7 +18,7 @@ RUN chmod +x docker-entrypoint.sh
...
@@ -18,7 +18,7 @@ RUN chmod +x docker-entrypoint.sh
RUN
make
install
RUN
make
install
# 设置环境变量
# 设置环境变量
ENV
APP_PORT_1=80
8
0
ENV
APP_PORT_1=80
0
0
# 暴露端口
# 暴露端口
EXPOSE
$APP_PORT_1
EXPOSE
$APP_PORT_1
...
...
Makefile
View file @
528b1483
...
@@ -3,7 +3,7 @@ APP_NAME = cangjie1.0.1-hello-world
...
@@ -3,7 +3,7 @@ APP_NAME = cangjie1.0.1-hello-world
CANGJIE_VERSION
=
1.0.1
CANGJIE_VERSION
=
1.0.1
MAIN_MODULE
=
HelloWorld
MAIN_MODULE
=
HelloWorld
BUILD_DIR
=
target
BUILD_DIR
=
target
APP_PORT
=
$
(
or
$(APP_PORT_1)
,80
8
0
)
APP_PORT
=
$
(
or
$(APP_PORT_1)
,80
0
0
)
LOG_FILE
=
$
(
abspath
$
(
dir
$
(
lastword
$(MAKEFILE_LIST)
)))
/.logs/app.log
LOG_FILE
=
$
(
abspath
$
(
dir
$
(
lastword
$(MAKEFILE_LIST)
)))
/.logs/app.log
PID_FILE
=
$
(
abspath
$
(
dir
$
(
lastword
$(MAKEFILE_LIST)
)))
/.logs/app.pid
PID_FILE
=
$
(
abspath
$
(
dir
$
(
lastword
$(MAKEFILE_LIST)
)))
/.logs/app.pid
...
@@ -131,4 +131,4 @@ help:
...
@@ -131,4 +131,4 @@ help:
@
echo
" make restart # 重启服务器"
@
echo
" make restart # 重启服务器"
@
echo
""
@
echo
""
@
echo
"环境变量:"
@
echo
"环境变量:"
@
echo
" APP_PORT_1 - 服务器端口(默认: 80
8
0)"
@
echo
" APP_PORT_1 - 服务器端口(默认: 80
0
0)"
README.md
View file @
528b1483
...
@@ -42,7 +42,7 @@ cangjie1_0_1_template/
...
@@ -42,7 +42,7 @@ cangjie1_0_1_template/
cjpm build
cjpm build
# 运行 HTTP 服务器
# 运行 HTTP 服务器
APP_PORT_1
=
80
8
0 cjpm run
APP_PORT_1
=
80
0
0 cjpm run
```
```
### 方法二:使用 Makefile
### 方法二:使用 Makefile
...
@@ -80,10 +80,10 @@ make help
...
@@ -80,10 +80,10 @@ make help
docker build
-t
cangjie1.0.1-hello-world
.
docker build
-t
cangjie1.0.1-hello-world
.
# 运行容器
# 运行容器
docker run
-p
80
80:808
0 cangjie1.0.1-hello-world
docker run
-p
80
00:800
0 cangjie1.0.1-hello-world
# 运行容器并指定端口
# 运行容器并指定端口
docker run
-p
9090:80
80
-e
APP_PORT_1
=
808
0 cangjie1.0.1-hello-world
docker run
-p
9090:80
00
-e
APP_PORT_1
=
800
0 cangjie1.0.1-hello-world
```
```
## 服务器使用示例
## 服务器使用示例
...
@@ -93,12 +93,12 @@ docker run -p 9090:8080 -e APP_PORT_1=8080 cangjie1.0.1-hello-world
...
@@ -93,12 +93,12 @@ docker run -p 9090:8080 -e APP_PORT_1=8080 cangjie1.0.1-hello-world
make run
make run
# 输出:
# 输出:
# ✅ 仓颉 HTTP 服务器已启动,PID: 12345
# ✅ 仓颉 HTTP 服务器已启动,PID: 12345
# 服务器运行在: http://localhost:80
8
0/
# 服务器运行在: http://localhost:80
0
0/
```
```
### 访问服务器
### 访问服务器
```
bash
```
bash
curl http://localhost:80
8
0/
curl http://localhost:80
0
0/
# 输出:Hello Cangjie!
# 输出:Hello Cangjie!
```
```
...
@@ -107,7 +107,7 @@ curl http://localhost:8080/
...
@@ -107,7 +107,7 @@ curl http://localhost:8080/
make status
make status
# 输出:
# 输出:
# ✅ 服务器正在运行,PID: 12345
# ✅ 服务器正在运行,PID: 12345
# 端口: 80
8
0
# 端口: 80
0
0
# 日志: /path/to/.logs/app.log
# 日志: /path/to/.logs/app.log
```
```
...
@@ -126,7 +126,7 @@ make stop
...
@@ -126,7 +126,7 @@ make stop
HTTP 服务器类包含以下功能:
HTTP 服务器类包含以下功能:
-
**main 函数**
: 程序入口点,启动 HTTP 服务器
-
**main 函数**
: 程序入口点,启动 HTTP 服务器
-
**端口配置**
: 硬编码端口 80
8
0,可通过环境变量 APP_PORT_1 覆盖
-
**端口配置**
: 硬编码端口 80
0
0,可通过环境变量 APP_PORT_1 覆盖
-
**HTTP 处理器**
: 使用 Lambda 表达式处理 HTTP 请求
-
**HTTP 处理器**
: 使用 Lambda 表达式处理 HTTP 请求
-
**服务器启动**
: 使用仓颉原生 HTTP 库创建 HTTP 服务
-
**服务器启动**
: 使用仓颉原生 HTTP 库创建 HTTP 服务
...
@@ -156,11 +156,11 @@ HTTP 服务器类包含以下功能:
...
@@ -156,11 +156,11 @@ HTTP 服务器类包含以下功能:
-
基于仓颉 1.0.1 镜像
-
基于仓颉 1.0.1 镜像
-
使用 cjpm 编译和运行 HTTP 服务器
-
使用 cjpm 编译和运行 HTTP 服务器
-
支持端口配置(APP_PORT_1 环境变量)
-
支持端口配置(APP_PORT_1 环境变量)
-
暴露 80
8
0 端口
-
暴露 80
0
0 端口
## 环境变量
## 环境变量
-
`APP_PORT_1`
: HTTP 服务器端口号(默认: 80
80,代码中硬编码为 808
0)
-
`APP_PORT_1`
: HTTP 服务器端口号(默认: 80
00,代码中硬编码为 800
0)
## 仓颉语言特性
## 仓颉语言特性
...
@@ -188,7 +188,7 @@ HTTP 服务器类包含以下功能:
...
@@ -188,7 +188,7 @@ HTTP 服务器类包含以下功能:
## 注意事项
## 注意事项
-
当前代码中端口硬编码为 80
8
0,环境变量 APP_PORT_1 暂时未生效
-
当前代码中端口硬编码为 80
0
0,环境变量 APP_PORT_1 暂时未生效
-
项目使用 cjpm 作为包管理器,需要确保已安装 cjpm
-
项目使用 cjpm 作为包管理器,需要确保已安装 cjpm
-
编译后的文件位于
`target`
目录
-
编译后的文件位于
`target`
目录
...
...
cjpm.toml
View file @
528b1483
[package]
[package]
cjc-version
=
"1.0.1"
cjc-version
=
"1.0.1"
name
=
"
cangjie1_0_1_templat
e"
name
=
"
workspac
e"
description
=
"仓颉1.0.1 HTTP服务器示例"
description
=
"仓颉1.0.1 HTTP服务器示例"
version
=
"1.0.0"
version
=
"1.0.0"
target-dir
=
""
target-dir
=
""
...
@@ -13,7 +13,13 @@
...
@@ -13,7 +13,13 @@
[dependencies]
[dependencies]
[target.aarch64-apple-darwin]
[target.aarch64-apple-darwin]
link-option
=
"-L/opt/homebrew/lib -lssl -lcrypto"
link-option
=
"-L/opt/homebrew/lib -lssl -lcrypto"
[target.aarch64-apple-darwin.bin-dependencies]
[target.aarch64-apple-darwin.bin-dependencies]
path-option
=
[
"${CANGJIE_STDX_PATH}/darwin_aarch64_llvm/dynamic/stdx"
]
path-option
=
[
"${CANGJIE_STDX_PATH}/darwin_aarch64_llvm/dynamic/stdx"
]
\ No newline at end of file
[target.x86_64-unknown-linux-gnu]
[target.x86_64-unknown-linux-gnu.bin-dependencies]
path-option
=
["${CANGJIE_STDX_PATH}/linux_x86_64_llvm/static/stdx"]
\ No newline at end of file
docker-entrypoint.sh
View file @
528b1483
...
@@ -7,7 +7,7 @@ set -e
...
@@ -7,7 +7,7 @@ set -e
echo
"=== 仓颉 1.0.1 HTTP 服务器容器启动 ==="
echo
"=== 仓颉 1.0.1 HTTP 服务器容器启动 ==="
echo
"仓颉版本:
$(
cjc
-v
2>&1 |
head
-n
1
)
"
echo
"仓颉版本:
$(
cjc
-v
2>&1 |
head
-n
1
)
"
echo
"工作目录:
$(
pwd
)
"
echo
"工作目录:
$(
pwd
)
"
echo
"端口:
${
APP_PORT_1
:-
80
8
0
}
"
echo
"端口:
${
APP_PORT_1
:-
80
0
0
}
"
echo
""
echo
""
# 检查仓颉编译器是否可用
# 检查仓颉编译器是否可用
...
@@ -30,6 +30,6 @@ fi
...
@@ -30,6 +30,6 @@ fi
# 运行HTTP服务器
# 运行HTTP服务器
echo
"启动仓颉 HTTP 服务器..."
echo
"启动仓颉 HTTP 服务器..."
echo
"服务器将在端口
${
APP_PORT_1
:-
80
8
0
}
上运行"
echo
"服务器将在端口
${
APP_PORT_1
:-
80
0
0
}
上运行"
echo
"=========================================="
echo
"=========================================="
exec
cjpm run
exec
cjpm run
src/helloworld.cj
View file @
528b1483
package
cangjie1_0_1_templat
e
package
workspac
e
import
stdx
.
net
.
http
.*
import
stdx
.
net
.
http
.*
import
std
.
time
.*
import
std
.
time
.*
...
@@ -11,8 +11,8 @@ import std.core.*
...
@@ -11,8 +11,8 @@ import std.core.*
*
使用仓颉原生
HTTP
库实现
HTTP
服务
*
使用仓颉原生
HTTP
库实现
HTTP
服务
*/
*/
main
()
{
main
()
{
//
从环境变量获取端口,默认为
80
8
0
//
从环境变量获取端口,默认为
80
0
0
let
port
:
UInt16
=
80
8
0
let
port
:
UInt16
=
80
0
0
//
构建
Server
实例
//
构建
Server
实例
...
@@ -29,7 +29,7 @@ main() {
...
@@ -29,7 +29,7 @@ main() {
//
设置日志级别
//
设置日志级别
server
.
logger
.
level
=
LogLevel
.
OFF
server
.
logger
.
level
=
LogLevel
.
OFF
println
(
"仓颉 HTTP 服务器运行在 http://0.0.0.0:80
8
0"
+
"/"
)
println
(
"仓颉 HTTP 服务器运行在 http://0.0.0.0:80
0
0"
+
"/"
)
//
启动服务
//
启动服务
server
.
serve
()
server
.
serve
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment