瀏覽代碼

更新项目结构和文档

删除了构建脚本`build.bt.sh`,更新了多个文件中的导入路径以匹配新的项目结构,并且丰富了README.md文件内容,添加了关于命令行参数、环境变量配置及路由信息的详细说明。同时新增了一些GitHub Issue模板和PR模板,以便更好地管理和接收社区反馈。
SongZihuan 3 月之前
父節點
當前提交
d71ed38411

+ 41 - 0
.github/ISSUE_TEMPLATE/1-bug.md

@@ -0,0 +1,41 @@
+---
+name: 遇到错误或反常情况
+about: 如果你遇到Bug(错误、不合理的情况)请通过此Issue反馈。
+---
+## Bug提交
+### 问题
+
+请简单概况问题。
+
+### 发生阶段
+
+* 运行(`go run`)
+* 构建(`go build`)
+* 构建后运行
+* 其他(请详细描述)
+
+(请在上述类型中选择或自行补充)
+
+### 你再做什么
+
+请详细说明你在做什么。
+
+### 项目运行的情况
+
+项目运行的情况是什么?
+
+例如:调用了某个API,数据库的写入或读取。
+
+### 发生了什么事情
+
+发生了什么错误?
+
+并且请把日志(若有)、命令行输出一并告诉我们。
+
+### 正确到结果应该是
+
+你希望正常的结果应该是什么?
+
+### 其他补充
+
+你的其他补充。

+ 15 - 0
.github/ISSUE_TEMPLATE/2-feature.md

@@ -0,0 +1,15 @@
+---
+name: 新功能请求
+about: 如果你有新功能请求,欢迎你告知我们。
+---
+## 新功能请求
+
+请简单概述你的功能请求。
+
+## 现状
+
+关于此功能的现状如何?
+
+* 我有想法,但我没办法自己实现
+* 我有想法,并且我计划自己实现并提交PR
+* 我已经提交PR

+ 7 - 0
.github/ISSUE_TEMPLATE/3-thank.md

@@ -0,0 +1,7 @@
+---
+name: 分享喜悦
+about: 如果我们的项目对你有帮助,或者你想分享一些喜悦(和项目有关的)欢迎使用此模板。
+---
+## 分享喜悦
+
+请简单叙述发生的事情,并为我们留言吧。

+ 1 - 0
.github/ISSUE_TEMPLATE/config.yaml

@@ -0,0 +1 @@
+blank_issues_enabled: true

+ 14 - 0
.github/pull-request-template.md

@@ -0,0 +1,14 @@
+<!-- 请务必在创建PR前,在右侧 Labels 选项中加上label的其中一个: [feature]、[fix]、[documentation] 。以便于Actions自动生成Releases时自动对PR进行归类。-->
+
+**在提出此拉取请求时,我确认了以下几点(请复选框):**
+
+- [ ] 我已阅读并理解[LICENSE](LICENSE),并自愿成为本项目的贡献者。
+- [ ] 我已检查没有与此请求重复的拉取请求。
+- [ ] 我已经考虑过,并确认这份呈件对其他人很有价值。
+- [ ] 我接受此提交可能不会被使用,并根据维护人员的意愿关闭拉取请求。
+
+**填写PR内容:**
+
+-
+-
+-

+ 42 - 2
README.md

@@ -3,8 +3,48 @@
 
 主要用于打印一些网络信息,便于测试。
 
-## 配置
-默认监听端口`:3366`,可通过`--address`和`-a`参数更改。
+## 命令行参数
+### HTTP
+Http默认监听端口`:3366`,可通过`--address`和`-http-address`参数更改。
+
+### HTTPS
+Https默认不监听,可通过`--https-address`参数开启监听。
+
+HTTPS默认使用acme的DNS-01调整申请HTTPS证书,因此你需要配置:`--https-domain`域名,`--https-aliyun-dns-access-key`和`--https-aliyun-dns-access-secret`阿里云具有DNS权限的RAM用户的Key和Secret。
+你还可以选择性配置`--https-email`,申请CA联系人你(不会体现在证书上),默认为`no-reply@example.com`。
+你还可以选择性配置`--https-cert-dir`,保存证书和和账号信息(每个邮箱都会对应一个账户),默认为当前目录下`ssl-certs`文件夹。
+
+## 环境变量
+通过环境变量也可以设置参数,但是会被命令行参数覆盖
+
+`DH_HTTP_ADDRESS`等价于`--http-address`。
+
+`DH_HTTPS_ADDRESS`等价于`--https-address`。
+
+`DH_HTTPS_DOMAIN`等价于`--https-domain`。
+
+`DH_HTTPS_EMAIL`等价于`--https-email`。
+
+`DH_HTTPS_CERT_DIR`等价于`--http-cert-dir`。
+
+`DH_HTTPS_ALIYUN_KEY`等价于`--https-aliyun-dns-access-key`。
+
+`DH_HTTPS_ALIYUN_SECRET`等价于`--https-aliyun-dns-access-secret`。
+
+## 路由
+`/` - 打印请求信息
+
+`/ip` - 打印接收请求时对方的IP地址,未必为请求人的IP地址,可能是代理的地址。
+
+`/client/ip` - 请取人的地址,通过请求头X-Forwarder-For等获取
+
+`/timestamp` - 当前时间戳
+
+`/datetime` - 当前时间
+
+`/hello` - 打印欢迎信息
+
+`/empty` - 返回204,无body
 
 ## 协议
 本软件基于[MIT LICENSE](./LICENSE)协议发布。

+ 13 - 0
REEPORT

@@ -0,0 +1,13 @@
+How to report of HTTP-DEMO
+
+Author: 宋子桓(Song Zihuan)
+Author Github: https://github.com/SongZihuan
+Author Website: https://song-zh.com
+Author Email: songzihuan@song-zh.com
+
+Github: https://github.com/SongZihuan/http-demo
+Github Issues: https://github.com/SongZihuan/http-demo/issues
+
+Report: You can report issues and contact the author through Github Issues or Author Email.
+Quality Assurance: If you only have the license in the LICENSE file in the root directory of this project, you will not get any quality assurance. But the author is happy to solve the problem for you, unless this project has been archived as read-only.
+Other Fork versions: Please contact the author of the Fork version for assistance.

+ 0 - 18
build.bt.sh

@@ -1,18 +0,0 @@
-#!/bin/sh
-# Just use in BT
-
-cd `dirname $0`
-
-time=$(date "+%Y-%m-%d %H:%M:%S")
-
-echo "start run, time: ${time}"
-
-PATH=/usr/local/btgojdk/go1.23.4/bin:$PATH
-
-rm -f ./http-demo
-
-go version && echo "start go mod tidy" && go mod tidy && echo "start go build" && go build -o ./http-demo github.com/SongZihuan/Http-Demo/src/cmd/v1 && echo "build finished"
-
-ls -al ./ | grep http-demo
-
-echo "run finished"

+ 1 - 1
go.mod

@@ -1,4 +1,4 @@
-module github.com/SongZihuan/Http-Demo
+module github.com/SongZihuan/http-demo
 
 go 1.22.0
 

+ 1 - 1
src/certssl/account/data.go

@@ -4,7 +4,7 @@ import (
 	"crypto"
 	"encoding/json"
 	"fmt"
-	"github.com/SongZihuan/Http-Demo/src/utils"
+	"github.com/SongZihuan/http-demo/src/utils"
 	"github.com/go-acme/lego/v4/certcrypto"
 	"github.com/go-acme/lego/v4/lego"
 	"github.com/go-acme/lego/v4/registration"

+ 2 - 2
src/certssl/applycert/main.go

@@ -2,8 +2,8 @@ package applycert
 
 import (
 	"fmt"
-	"github.com/SongZihuan/Http-Demo/src/certssl/account"
-	"github.com/SongZihuan/Http-Demo/src/utils"
+	"github.com/SongZihuan/http-demo/src/certssl/account"
+	"github.com/SongZihuan/http-demo/src/utils"
 	"github.com/go-acme/lego/v4/certcrypto"
 	"github.com/go-acme/lego/v4/certificate"
 	"github.com/go-acme/lego/v4/lego"

+ 2 - 2
src/certssl/applycert/read.go

@@ -4,8 +4,8 @@ import (
 	"crypto"
 	"crypto/x509"
 	"fmt"
-	"github.com/SongZihuan/Http-Demo/src/certssl/filename"
-	"github.com/SongZihuan/Http-Demo/src/utils"
+	"github.com/SongZihuan/http-demo/src/certssl/filename"
+	"github.com/SongZihuan/http-demo/src/utils"
 	"os"
 	"path"
 )

+ 2 - 2
src/certssl/applycert/write.go

@@ -2,8 +2,8 @@ package applycert
 
 import (
 	"fmt"
-	"github.com/SongZihuan/Http-Demo/src/certssl/filename"
-	"github.com/SongZihuan/Http-Demo/src/utils"
+	"github.com/SongZihuan/http-demo/src/certssl/filename"
+	"github.com/SongZihuan/http-demo/src/utils"
 	"github.com/go-acme/lego/v4/certificate"
 	"os"
 	"path"

+ 2 - 2
src/certssl/main.go

@@ -4,8 +4,8 @@ import (
 	"crypto"
 	"crypto/x509"
 	"fmt"
-	"github.com/SongZihuan/Http-Demo/src/certssl/applycert"
-	"github.com/SongZihuan/Http-Demo/src/utils"
+	"github.com/SongZihuan/http-demo/src/certssl/applycert"
+	"github.com/SongZihuan/http-demo/src/utils"
 	"time"
 )
 

+ 1 - 1
src/cmd/version1/main.go

@@ -1,7 +1,7 @@
 package main
 
 import (
-	"github.com/SongZihuan/Http-Demo/src/mainfunc"
+	"github.com/SongZihuan/http-demo/src/mainfunc"
 	"os"
 )
 

+ 1 - 1
src/engine/engine.go

@@ -1,7 +1,7 @@
 package engine
 
 import (
-	"github.com/SongZihuan/Http-Demo/src/handler"
+	"github.com/SongZihuan/http-demo/src/handler"
 	"github.com/gin-gonic/gin"
 )
 

+ 1 - 1
src/handler/message.go

@@ -2,7 +2,7 @@ package handler
 
 import (
 	"fmt"
-	resource "github.com/SongZihuan/Http-Demo"
+	resource "github.com/SongZihuan/http-demo"
 	"github.com/gin-gonic/gin"
 	"net/http"
 	"strings"

+ 2 - 2
src/httpserver/server.go

@@ -3,8 +3,8 @@ package httpserver
 import (
 	"errors"
 	"fmt"
-	"github.com/SongZihuan/Http-Demo/src/engine"
-	"github.com/SongZihuan/Http-Demo/src/flagparser"
+	"github.com/SongZihuan/http-demo/src/engine"
+	"github.com/SongZihuan/http-demo/src/flagparser"
 	"net/http"
 )
 

+ 3 - 3
src/httpsslserver/server.go

@@ -7,9 +7,9 @@ import (
 	"crypto/x509"
 	"errors"
 	"fmt"
-	"github.com/SongZihuan/Http-Demo/src/certssl"
-	"github.com/SongZihuan/Http-Demo/src/engine"
-	"github.com/SongZihuan/Http-Demo/src/flagparser"
+	"github.com/SongZihuan/http-demo/src/certssl"
+	"github.com/SongZihuan/http-demo/src/engine"
+	"github.com/SongZihuan/http-demo/src/flagparser"
 	"net/http"
 	"sync"
 	"time"

+ 6 - 6
src/mainfunc/version1.go

@@ -3,12 +3,12 @@ package mainfunc
 import (
 	"errors"
 	"fmt"
-	resource "github.com/SongZihuan/Http-Demo"
-	"github.com/SongZihuan/Http-Demo/src/engine"
-	"github.com/SongZihuan/Http-Demo/src/flagparser"
-	"github.com/SongZihuan/Http-Demo/src/httpserver"
-	"github.com/SongZihuan/Http-Demo/src/httpsslserver"
-	"github.com/SongZihuan/Http-Demo/src/signalchan"
+	resource "github.com/SongZihuan/http-demo"
+	"github.com/SongZihuan/http-demo/src/engine"
+	"github.com/SongZihuan/http-demo/src/flagparser"
+	"github.com/SongZihuan/http-demo/src/httpserver"
+	"github.com/SongZihuan/http-demo/src/httpsslserver"
+	"github.com/SongZihuan/http-demo/src/signalchan"
 )
 
 func MainV1() (exitcode int) {