mirror of
https://github.com/number571/go-peer.git
synced 2026-09-14 11:05:42 +05:00
update
This commit is contained in:
parent
2b677f751e
commit
1691e9a92b
5
TODO.md
5
TODO.md
@ -3,6 +3,5 @@
|
||||
1. Append comments for functions/variables/constants/etc (doc)
|
||||
2. Append benchmarks
|
||||
3. Write tests for coverage > 70%
|
||||
4. Arguments with prefix 'p'
|
||||
5. Develop union_blockchain
|
||||
6. Write linters (names with prefixes 'p', 'f', 's', 'i', 'c', 'g'), (objects with name=p)
|
||||
4. Develop union_blockchain
|
||||
5. Write linters (names with prefixes 'p', 'f', 's', 'i', 'c', 'g'), (objects with name=p)
|
||||
|
||||
@ -8,14 +8,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Request(client *http.Client, method, url string, data interface{}) (string, error) {
|
||||
func Request(pClient *http.Client, pMethod, pURL string, pData interface{}) (string, error) {
|
||||
var requestBytes []byte
|
||||
|
||||
switch x := data.(type) {
|
||||
switch x := pData.(type) {
|
||||
case []byte:
|
||||
requestBytes = x
|
||||
default:
|
||||
jsonValue, err := json.Marshal(data)
|
||||
jsonValue, err := json.Marshal(pData)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -23,8 +23,8 @@ func Request(client *http.Client, method, url string, data interface{}) (string,
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(
|
||||
method,
|
||||
url,
|
||||
pMethod,
|
||||
pURL,
|
||||
bytes.NewBuffer(requestBytes),
|
||||
)
|
||||
if err != nil {
|
||||
@ -32,7 +32,7 @@ func Request(client *http.Client, method, url string, data interface{}) (string,
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", CContentType)
|
||||
resp, err := client.Do(req)
|
||||
resp, err := pClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -46,8 +46,8 @@ func Request(client *http.Client, method, url string, data interface{}) (string,
|
||||
return res.FResult, nil
|
||||
}
|
||||
|
||||
func loadResponse(reader io.ReadCloser) (*SResponse, error) {
|
||||
body, err := io.ReadAll(reader)
|
||||
func loadResponse(pReader io.ReadCloser) (*SResponse, error) {
|
||||
body, err := io.ReadAll(pReader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -5,10 +5,10 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Response(w http.ResponseWriter, ret int, res string) {
|
||||
w.Header().Set("Content-Type", CContentType)
|
||||
json.NewEncoder(w).Encode(&SResponse{
|
||||
FResult: res,
|
||||
FReturn: ret,
|
||||
func Response(pW http.ResponseWriter, pRet int, pRes string) {
|
||||
pW.Header().Set("Content-Type", CContentType)
|
||||
json.NewEncoder(pW).Encode(&SResponse{
|
||||
FResult: pRes,
|
||||
FReturn: pRet,
|
||||
})
|
||||
}
|
||||
|
||||
@ -6,19 +6,19 @@ import (
|
||||
"github.com/number571/go-peer/pkg/logger"
|
||||
)
|
||||
|
||||
func StdLogger(logging ILogging) logger.ILogger {
|
||||
return logger.NewLogger(defaultSettings(logging))
|
||||
func StdLogger(pLogging ILogging) logger.ILogger {
|
||||
return logger.NewLogger(defaultSettings(pLogging))
|
||||
}
|
||||
|
||||
func defaultSettings(logging ILogging) logger.ISettings {
|
||||
func defaultSettings(pLogging ILogging) logger.ISettings {
|
||||
sett := &logger.SSettings{}
|
||||
if logging.HasInfo() {
|
||||
if pLogging.HasInfo() {
|
||||
sett.FInfo = os.Stdout
|
||||
}
|
||||
if logging.HasWarn() {
|
||||
if pLogging.HasWarn() {
|
||||
sett.FWarn = os.Stdout
|
||||
}
|
||||
if logging.HasErro() {
|
||||
if pLogging.HasErro() {
|
||||
sett.FErro = os.Stderr
|
||||
}
|
||||
return logger.NewSettings(sett)
|
||||
|
||||
@ -13,27 +13,27 @@ import (
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
func RunPprofService(service string) {
|
||||
func RunPprofService(pService string) {
|
||||
logger := logger.NewLogger(logger.NewSettings(&logger.SSettings{
|
||||
FInfo: os.Stdout,
|
||||
FWarn: os.Stdout,
|
||||
FErro: os.Stderr,
|
||||
}))
|
||||
go runPprofService(logger, service)
|
||||
go runPprofService(logger, pService)
|
||||
time.Sleep(cWaitTime)
|
||||
}
|
||||
|
||||
func runPprofService(logger logger.ILogger, service string) {
|
||||
func runPprofService(pLogger logger.ILogger, pService string) {
|
||||
for i := 0; i < cRetriesNum; i++ {
|
||||
port := random.NewStdPRNG().GetUint64()%(4<<10) + 60000 // [60000;64096]
|
||||
logger.PushInfo(fmt.Sprintf("%s => pprof running on %d port", service, port))
|
||||
pLogger.PushInfo(fmt.Sprintf("%s => pprof running on %d port", pService, port))
|
||||
|
||||
err := http.ListenAndServe(fmt.Sprintf("localhost:%d", port), nil)
|
||||
if err != nil && errors.Is(err, http.ErrServerClosed) {
|
||||
logger.PushWarn(fmt.Sprintf("%s => pprof service is closed", service))
|
||||
pLogger.PushWarn(fmt.Sprintf("%s => pprof service is closed", pService))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
logger.PushErro(fmt.Sprintf("%s => pprof failed running", service))
|
||||
pLogger.PushErro(fmt.Sprintf("%s => pprof failed running", pService))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user