-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
384 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package model | ||
|
||
type NAT struct { | ||
Common | ||
Name string | ||
ServerID uint64 | ||
Host string | ||
Domain string `gorm:"unique"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package utils | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"net" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
var _ io.ReadWriteCloser = &RequestWrapper{} | ||
|
||
type RequestWrapper struct { | ||
req *http.Request | ||
reader *bytes.Buffer | ||
writer net.Conn | ||
} | ||
|
||
func NewRequestWrapper(req *http.Request, writer gin.ResponseWriter) (*RequestWrapper, error) { | ||
conn, _, err := writer.Hijack() | ||
if err != nil { | ||
return nil, err | ||
} | ||
buf := bytes.NewBuffer(nil) | ||
if err = req.Write(buf); err != nil { | ||
return nil, err | ||
} | ||
return &RequestWrapper{ | ||
req: req, | ||
reader: buf, | ||
writer: conn, | ||
}, nil | ||
} | ||
|
||
func (rw *RequestWrapper) Read(p []byte) (int, error) { | ||
count, err := rw.reader.Read(p) | ||
if err == nil { | ||
return count, nil | ||
} | ||
if err != io.EOF { | ||
return count, err | ||
} | ||
// request 数据读完之后等待客户端断开连接或 grpc 超时 | ||
return rw.writer.Read(p) | ||
} | ||
|
||
func (rw *RequestWrapper) Write(p []byte) (int, error) { | ||
return rw.writer.Write(p) | ||
} | ||
|
||
func (rw *RequestWrapper) Close() error { | ||
rw.req.Body.Close() | ||
rw.writer.Close() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.