mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-02-03 17:01:11 +08:00
Compare commits
No commits in common. "e77fcb10d3e66adfe393df98e2f08a36c86a7e14" and "e10c20c5d6fb81078d994f26dfd8872ff78a467d" have entirely different histories.
e77fcb10d3
...
e10c20c5d6
20 changed files with 9 additions and 1144 deletions
24
.github/workflows/test.yml
vendored
24
.github/workflows/test.yml
vendored
|
|
@ -1,24 +0,0 @@
|
||||||
name: Go Test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.24'
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: go test -v ./...
|
|
||||||
|
|
||||||
- name: Run tests race
|
|
||||||
run: go test -race -v ./...
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 文件: touka/adapter.go
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
16
context.go
16
context.go
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -27,7 +23,7 @@ import (
|
||||||
"github.com/fenthope/reco"
|
"github.com/fenthope/reco"
|
||||||
"github.com/go-json-experiment/json"
|
"github.com/go-json-experiment/json"
|
||||||
|
|
||||||
"github.com/WJQSERVER-STUDIO/go-utils/iox"
|
"github.com/WJQSERVER-STUDIO/go-utils/copyb"
|
||||||
"github.com/WJQSERVER-STUDIO/httpc"
|
"github.com/WJQSERVER-STUDIO/httpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -435,7 +431,7 @@ func (c *Context) WriteStream(reader io.Reader) (written int64, err error) {
|
||||||
c.Writer.WriteHeader(http.StatusOK) // 默认 200 OK
|
c.Writer.WriteHeader(http.StatusOK) // 默认 200 OK
|
||||||
}
|
}
|
||||||
|
|
||||||
written, err = iox.Copy(c.Writer, reader) // 从 reader 读取并写入 ResponseWriter
|
written, err = copyb.Copy(c.Writer, reader) // 从 reader 读取并写入 ResponseWriter
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AddError(fmt.Errorf("failed to write stream: %w", err))
|
c.AddError(fmt.Errorf("failed to write stream: %w", err))
|
||||||
}
|
}
|
||||||
|
|
@ -475,7 +471,7 @@ func (c *Context) GetReqBodyFull() ([]byte, error) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := iox.ReadAll(limitBytesReader)
|
data, err := copyb.ReadAll(limitBytesReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AddError(fmt.Errorf("failed to read request body: %w", err))
|
c.AddError(fmt.Errorf("failed to read request body: %w", err))
|
||||||
return nil, fmt.Errorf("failed to read request body: %w", err)
|
return nil, fmt.Errorf("failed to read request body: %w", err)
|
||||||
|
|
@ -509,7 +505,7 @@ func (c *Context) GetReqBodyBuffer() (*bytes.Buffer, error) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := iox.ReadAll(limitBytesReader)
|
data, err := copyb.ReadAll(limitBytesReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AddError(fmt.Errorf("failed to read request body: %w", err))
|
c.AddError(fmt.Errorf("failed to read request body: %w", err))
|
||||||
return nil, fmt.Errorf("failed to read request body: %w", err)
|
return nil, fmt.Errorf("failed to read request body: %w", err)
|
||||||
|
|
@ -682,7 +678,7 @@ func (c *Context) SetBodyStream(reader io.Reader, contentSize int) {
|
||||||
|
|
||||||
// 将 reader 的内容直接复制到 ResponseWriter
|
// 将 reader 的内容直接复制到 ResponseWriter
|
||||||
// ResponseWriter 实现了 io.Writer 接口
|
// ResponseWriter 实现了 io.Writer 接口
|
||||||
_, err := iox.Copy(c.Writer, reader)
|
_, err := copyb.Copy(c.Writer, reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AddError(fmt.Errorf("failed to write stream: %w", err))
|
c.AddError(fmt.Errorf("failed to write stream: %w", err))
|
||||||
// 注意:这里可能无法设置错误状态码,因为头部可能已经发送
|
// 注意:这里可能无法设置错误状态码,因为头部可能已经发送
|
||||||
|
|
@ -741,7 +737,7 @@ func (c *Context) SetRespBodyFile(code int, filePath string) {
|
||||||
c.Writer.WriteHeader(code)
|
c.Writer.WriteHeader(code)
|
||||||
|
|
||||||
// 将文件内容写入响应体
|
// 将文件内容写入响应体
|
||||||
_, err = iox.Copy(c.Writer, file)
|
_, err = copyb.Copy(c.Writer, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AddError(fmt.Errorf("failed to write file %s to response: %w", cleanPath, err))
|
c.AddError(fmt.Errorf("failed to write file %s to response: %w", cleanPath, err))
|
||||||
// 注意:这里可能无法设置错误状态码,因为头部可能已经发送
|
// 注意:这里可能无法设置错误状态码,因为头部可能已经发送
|
||||||
|
|
|
||||||
4
ecw.go
4
ecw.go
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
3
go.mod
3
go.mod
|
|
@ -3,14 +3,13 @@ module github.com/infinite-iroha/touka
|
||||||
go 1.24.4
|
go 1.24.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2
|
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6
|
||||||
github.com/WJQSERVER-STUDIO/httpc v0.8.1
|
github.com/WJQSERVER-STUDIO/httpc v0.8.1
|
||||||
github.com/fenthope/reco v0.0.3
|
github.com/fenthope/reco v0.0.3
|
||||||
github.com/go-json-experiment/json v0.0.0-20250714165856-be8212f5270d
|
github.com/go-json-experiment/json v0.0.0-20250714165856-be8212f5270d
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6 // indirect
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
golang.org/x/net v0.42.0 // indirect
|
golang.org/x/net v0.42.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -1,7 +1,5 @@
|
||||||
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6 h1:/50VJYXd6jcu+p5BnEBDyiX0nAyGxas1W3DCnrYMxMY=
|
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6 h1:/50VJYXd6jcu+p5BnEBDyiX0nAyGxas1W3DCnrYMxMY=
|
||||||
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc=
|
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc=
|
||||||
github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2 h1:AiIHXP21LpK7pFfqUlUstgQEWzjbekZgxOuvVwiMfyM=
|
|
||||||
github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2/go.mod h1:mCLqYU32bTmEE6dpj37MKKiZgz70Jh/xyK9vVbq6pok=
|
|
||||||
github.com/WJQSERVER-STUDIO/httpc v0.8.1 h1:/eG8aYKL3WfQILIRbG+cbzQjPkNHEPTqfGUdQS5rtI4=
|
github.com/WJQSERVER-STUDIO/httpc v0.8.1 h1:/eG8aYKL3WfQILIRbG+cbzQjPkNHEPTqfGUdQS5rtI4=
|
||||||
github.com/WJQSERVER-STUDIO/httpc v0.8.1/go.mod h1:mxXBf2hqbQGNHkVy/7wfU7Xi2s09MyZpbY2hyR+4uD4=
|
github.com/WJQSERVER-STUDIO/httpc v0.8.1/go.mod h1:mxXBf2hqbQGNHkVy/7wfU7Xi2s09MyZpbY2hyR+4uD4=
|
||||||
github.com/fenthope/reco v0.0.3 h1:RmnQ0D9a8PWtwOODawitTe4BztTnS9wYwrDbipISNq4=
|
github.com/fenthope/reco v0.0.3 h1:RmnQ0D9a8PWtwOODawitTe4BztTnS9wYwrDbipISNq4=
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
BSD 3-Clause License
|
|
||||||
|
|
||||||
Copyright (c) 2013, Julien Schmidt
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
type MiddlewareXFunc func() HandlerFunc
|
type MiddlewareXFunc func() HandlerFunc
|
||||||
|
|
|
||||||
4
path.go
4
path.go
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 文件: touka/recovery.go
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
4
respw.go
4
respw.go
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
4
serve.go
4
serve.go
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
4
touka.go
4
touka.go
|
|
@ -1,7 +1,3 @@
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
|
||||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
1021
tree_test.go
1021
tree_test.go
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue