Commit b40f8f9c authored by Ubuntu's avatar Ubuntu

debug http req body

parent d5e89bae
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs
import "github.com/swaggo/swag"
const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {}
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "",
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}
func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
{
"swagger": "2.0",
"info": {
"contact": {}
},
"paths": {}
}
\ No newline at end of file
openapi: 3.0.0
servers:
- url: http://43.198.54.207:8001
description: Default server
info:
description: |
This is a sample sniper wallet server.
## Introduction
This API is documented in **OpenAPI format** and is based on
version: 0.0.1
title: Swagger Uniswap Wallet YAML
termsOfService: "http://swagger.io/terms/"
contact:
name: API Support
email: apiteam@swagger.io
url: https://github.com/Redocly/redoc
x-logo:
url: "https://redocly.github.io/redoc/petstore-logo.png"
altText: Petstore logo
license:
name: Apache 2.0
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
externalDocs:
description: Find out how to create Github repo for your OpenAPI spec.
url: "https://github.com/Rebilly/generator-openapi-repo"
tags:
- name: Task
description: add or stop task
# - name: User
# description: Everything about user
# - name: store
# description: Access to Petstore orders
# x-displayName: Petstore Orders
# - name: user
# description: Operations about user
# x-displayName: Users
# - name: pet_model
# x-displayName: The Pet Model
# description: |
# <SchemaDefinition schemaRef="#/components/schemas/Pet" />
# - name: store_model
# x-displayName: The Order Model
# description: |
# <SchemaDefinition schemaRef="#/components/schemas/Order" exampleRef="#/components/examples/Order" showReadOnly={true} showWriteOnly={true} />
x-tagGroups:
- name: Task Controler
tags:
- task
- name: User Management
tags:
- user
- name: Models
tags:
- pet_model
- store_model
paths:
/task/add:
summary: Create or update a new task in the twitter syncer
post:
tags:
- Task
requestBody:
description: like 或 retweet 为true的时候,开启对应的同步任务;
content:
application/json:
schema:
type: object
$ref: "#/components/schemas/task"
responses:
"200":
description: successful operation
content:
application/json:
schema:
type: object
properties:
code:
type: integer
format: int64
enum: [200, 500]
msg:
type: string
/task/stop:
summary: Stop a task in the twitter syncer
post:
tags:
- Task
requestBody:
description: like 或 retweet 为true的时候,停止指定任务like或retweet;
content:
application/json:
schema:
type: object
$ref: "#/components/schemas/task"
responses:
"200":
description: successful operation
content:
application/json:
schema:
type: object
properties:
code:
type: integer
format: int64
enum: [200, 500]
msg:
type: string
components:
securitySchemes:
api_key:
description: |
For this sample, you can use the api key `special-key` to test the authorization filters.
in: header
name: api_key
type: apiKey
petstore_auth:
description: |
Get access to data while protecting your account credentials.
OAuth2 is also a safer and more secure way to give you access.
flows:
implicit:
authorizationUrl: http://petstore.swagger.io/api/oauth/dialog
scopes:
read:pets: read your pets
write:pets: modify pets in your account
type: oauth2
schemas:
task:
required:
- project
- tweet_id
type: object
properties:
project:
type: string
tweet_id:
type: string
like:
type: boolean
retweet:
type: boolean
module code.wuban.net.cn/odysseus/twitter_syncer
go 1.22.4
require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.2.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gofiber/fiber/v2 v2.52.5 // indirect
github.com/gofiber/swagger v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/swaggo/files/v2 v2.0.1 // indirect
github.com/swaggo/swag v1.16.3 // indirect
github.com/urfave/cli/v2 v2.27.3 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.23.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
This diff is collapsed.
package main
import (
"log/slog"
"time"
// "github.com/gofiber/fiber/v2"
// "github.com/gofiber/fiber/v2/middleware/cors"
// "github.com/gofiber/swagger"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/swagger"
// docs are generated by Swag CLI, you have to import them.
// replace with your own docs folder, usually "github.com/username/reponame/docs"
//_ "github.com/gofiber/swagger/example/docs"
)
func mainBak() {
app := fiber.New()
app.Use(cors.New())
// app.Get("/", func(c *fiber.Ctx) error {
// return c.SendString("OK")
// })
app.Static("/*", "./public", fiber.Static{
Compress: true,
ByteRange: true,
Browse: true,
CacheDuration: 10 * time.Second,
MaxAge: 3600,
Download: true,
})
// app.Static("/*", "./public/")
// app.Static("/swagger/docs", "./docs")
// app.Static("/swagger/docs", "./docs")
app.Get("/swagger/*", swagger.New(swagger.Config{ // custom
URL: "http://43.198.54.207:8001/swagger/docs/swagger.yaml", //http://124.193.167.71:8000/
DeepLinking: false,
// Expand ("list") or Collapse ("none") tag groups by default
DocExpansion: "none",
// Prefill OAuth ClientId on Authorize popup
// OAuth: &swagger.OAuthConfig{
// AppName: "OAuth Provider",
// ClientId: "21bb4edc-05a7-4afc-86f1-2e151e4ba6e2",
// },
// Ability to change OAuth2 redirect uri location
//OAuth2RedirectUrl: "http://localhost:8080/swagger/oauth2-redirect.html",
}))
// app.Static("/swagger/docs", "./docs")
// app.Get("/swagger/*", swagger.New(swagger.Config{ // custom
// URL: "http://43.198.54.207:8001/swagger/docs/swagger.yaml", //http://124.193.167.71:8000/
// DeepLinking: false,
// // Expand ("list") or Collapse ("none") tag groups by default
// DocExpansion: "none",
// // Prefill OAuth ClientId on Authorize popup
// // OAuth: &swagger.OAuthConfig{
// // AppName: "OAuth Provider",
// // ClientId: "21bb4edc-05a7-4afc-86f1-2e151e4ba6e2",
// // },
// // Ability to change OAuth2 redirect uri location
// //OAuth2RedirectUrl: "http://localhost:8080/swagger/oauth2-redirect.html",
// }))
if err := app.Listen(":8001"); err != nil {
slog.Error(err.Error())
}
}
package main
import (
"encoding/json"
"log/slog"
// "github.com/gofiber/fiber/v2"
// "github.com/gofiber/fiber/v2/middleware/cors"
// "github.com/gofiber/swagger"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/swagger"
//"github.com/gofiber/swagger"
_ "code.wuban.net.cn/odysseus/twitter_syncer/docs"
// docs are generated by Swag CLI, you have to import them.
// replace with your own docs folder, usually "github.com/username/reponame/docs"
//_ "github.com/gofiber/swagger/example/docs"
)
func main() {
app := fiber.New()
app.Use(cors.New())
app.Static("/swagger/docs", "./docs")
app.Get("/swagger/*", swagger.New(swagger.Config{ // custom
URL: "http://43.198.54.207:8001/swagger/docs/swagger.yaml", //http://124.193.167.71:8000/
DeepLinking: false,
// Expand ("list") or Collapse ("none") tag groups by default
DocExpansion: "none",
// Prefill OAuth ClientId on Authorize popup
// OAuth: &swagger.OAuthConfig{
// AppName: "OAuth Provider",
// ClientId: "21bb4edc-05a7-4afc-86f1-2e151e4ba6e2",
// },
// Ability to change OAuth2 redirect uri location
//OAuth2RedirectUrl: "http://localhost:8080/swagger/oauth2-redirect.html",
}))
app.Post("/task/add", func(c *fiber.Ctx) error {
//fmt.Println(string(c.Request().Body()))
slog.Info(c.Route().Path, "body", string(c.Request().Body()))
req := Req{}
if err := json.Unmarshal(c.Request().Body(), &req); err != nil {
return c.JSON(Res{
Code: 500,
Msg: err.Error(),
})
}
slog.Info(c.Route().Path, "Project", req.Project, "TweetId", req.TweetId, "Retweet", req.Retweet, "Like", req.Like)
if req.Project == "" || req.TweetId == "" {
return c.JSON(Res{
Code: 500,
Msg: "must provide project and tweet_id",
})
}
if !req.Like && !req.Retweet {
return c.JSON(Res{
Code: 200,
})
}
return c.JSON(Res{
Code: 200,
})
})
app.Post("/task/stop", func(c *fiber.Ctx) error {
slog.Info(c.Route().Path, "body", string(c.Request().Body()))
// fmt.Println(string(c.Request().Body()))
req := Req{}
if err := json.Unmarshal(c.Request().Body(), &req); err != nil {
return c.JSON(Res{
Code: 500,
Msg: err.Error(),
})
}
slog.Info(c.Route().Path, "Project", req.Project, "TweetId", req.TweetId, "Retweet", req.Retweet, "Like", req.Like)
if req.Project == "" || req.TweetId == "" {
return c.JSON(Res{
Code: 500,
Msg: "must provide project and tweet_id",
})
}
if !req.Like && !req.Retweet {
return c.JSON(Res{
Code: 200,
})
}
return c.JSON(Res{
Code: 200,
})
})
if err := app.Listen(":8001"); err != nil {
slog.Error(err.Error())
}
}
type Res struct {
Code int64 `json:"code"`
Msg string `json:"msg"`
}
type Req struct {
Project string `json:"project"`
TweetId string `json:"tweet_id"`
Like bool `json:"like"`
Retweet bool `json:"retweet"`
}
1234567890
\ No newline at end of file
openapi: 3.0.0
servers:
- url: http://124.193.167.71:6000/
description: Default server
info:
description: |
This is a sample sniper wallet server.
## Introduction
This API is documented in **OpenAPI format** and is based on
version: 0.0.1
title: Swagger Uniswap Wallet YAML
termsOfService: "http://swagger.io/terms/"
contact:
name: API Support
email: apiteam@swagger.io
url: https://github.com/Redocly/redoc
x-logo:
url: "https://redocly.github.io/redoc/petstore-logo.png"
altText: Petstore logo
license:
name: Apache 2.0
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
externalDocs:
description: Find out how to create Github repo for your OpenAPI spec.
url: "https://github.com/Rebilly/generator-openapi-repo"
tags:
- name: MonitorHardware
description: Everything about host hardware
# - name: User
# description: Everything about user
# - name: store
# description: Access to Petstore orders
# x-displayName: Petstore Orders
# - name: user
# description: Operations about user
# x-displayName: Users
# - name: pet_model
# x-displayName: The Pet Model
# description: |
# <SchemaDefinition schemaRef="#/components/schemas/Pet" />
# - name: store_model
# x-displayName: The Order Model
# description: |
# <SchemaDefinition schemaRef="#/components/schemas/Order" exampleRef="#/components/examples/Order" showReadOnly={true} showWriteOnly={true} />
x-tagGroups:
- name: General
tags:
- pet
- store
- name: User Management
tags:
- user
- name: Models
tags:
- pet_model
- store_model
paths:
/hw:
get:
summary: get host hardware info and usage
tags:
- MonitorHardware
responses:
"200":
description: successful operation
content:
application/json:
schema:
type: object
properties:
hardware:
$ref: "#/components/schemas/hw"
code:
type: integer
format: int64
enum: [200, 500]
msg:
type: string
components:
securitySchemes:
api_key:
description: |
For this sample, you can use the api key `special-key` to test the authorization filters.
in: header
name: api_key
type: apiKey
petstore_auth:
description: |
Get access to data while protecting your account credentials.
OAuth2 is also a safer and more secure way to give you access.
flows:
implicit:
authorizationUrl: http://petstore.swagger.io/api/oauth/dialog
scopes:
read:pets: read your pets
write:pets: modify pets in your account
type: oauth2
schemas:
hw:
type: object
properties:
CPU:
type: object
properties:
model:
type: string
number:
type: integer
format: int64
cores:
type: integer
format: int64
threads:
type: integer
format: int64
usage:
type: integer
format: int64
frequency:
type: string
GPU:
type: array
items:
$ref: "#/components/schemas/gpu"
RAM:
type: object
properties:
total:
type: integer
format: int64
free:
type: integer
format: int64
mem_util:
type: integer
format: int64
DISK:
type: array
items:
$ref: "#/components/schemas/filesystem"
NET:
type: array
items:
$ref: "#/components/schemas/network"
network:
type: object
properties:
device:
type: string
speed:
type: integer
format: int64
send_rate:
type: integer
format: int64
recv_rate:
type: integer
format: int64
filesystem:
type: object
properties:
device:
type: string
mount_points:
type: array
items:
type: string
free_bytes:
type: integer
format: int64
size_bytes:
type: integer
format: int64
gpu:
type: object
properties:
seq:
type: integer
format: int64
uuid:
type: string
model:
type: string
performance:
type: integer
format: int64
power_rating:
type: integer
format: int64
mem_total:
type: integer
format: int64
mem_free:
type: integer
format: int64
usage:
type: integer
format: int64
temp:
type: integer
format: int64
power_rt:
type: integer
format: int64
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment