237 lines
6.8 KiB
Go
237 lines
6.8 KiB
Go
//go:generate ${GOPATH}/bin/easyjson $GOFILE
|
|
package iface
|
|
|
|
import (
|
|
"bytes"
|
|
"time"
|
|
|
|
"amuz.es/gogs/infra/changer/enums"
|
|
)
|
|
|
|
//easyjson:json
|
|
type Login struct {
|
|
Id string `form:"id" json:"id" binding:"required"`
|
|
Password string `form:"password" json:"password" binding:"required"`
|
|
RedirectTo string `form:"redirect_to" json:"redirect_to,omitempty"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type ChangePassword struct {
|
|
OldPassword string `form:"old_password" json:"old_password" binding:"required"`
|
|
Password string `form:"password" json:"password" binding:"required"`
|
|
PasswordConfirm string `form:"password_confirm" json:"password_confirm" binding:"required"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type Token struct {
|
|
Token string `json:"token"`
|
|
Expire string `json:"expire"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type LoginResponse struct {
|
|
Message string `json:"message"`
|
|
RedirectTo string `json:"redirectTo,omitempty"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type WrappedResponse struct {
|
|
Message string `json:"message"`
|
|
Content interface{} `json:"content,omitempty"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type NewId struct {
|
|
Id interface{} `json:"id" binding:"required"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type NameCodePair struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Code string `json:"code" binding:"required"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type KeyValuePair struct {
|
|
Key string `json:"key" binding:"required"`
|
|
Value string `json:"value" binding:"required"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type Tuple struct {
|
|
Path string
|
|
Code int
|
|
}
|
|
|
|
//easyjson:json
|
|
type CounterMetric struct {
|
|
Inc chan Tuple `json:"-"`
|
|
internalRequestsSum uint64
|
|
internalRequests map[string]uint64
|
|
internalRequestCodes map[string]uint64
|
|
RequestsSum uint64 `json:"request_sum_per_minute"`
|
|
Requests map[string]uint64 `json:"requests_per_minute"`
|
|
RequestCodes map[string]uint64 `json:"request_codes_per_minute"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type DurationMetricReadable struct {
|
|
Min string `json:"min"`
|
|
Max string `json:"max"`
|
|
Mean string `json:"mean"`
|
|
Stdev string `json:"stdev"`
|
|
P90 string `json:"p90"`
|
|
P95 string `json:"p95"`
|
|
P99 string `json:"p99"`
|
|
|
|
Timestamp time.Time `json:"timestamp"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type DurationMetric struct {
|
|
Min uint64 `json:"min"`
|
|
Max uint64 `json:"max"`
|
|
Mean uint64 `json:"mean"`
|
|
Stdev uint64 `json:"stdev"`
|
|
P90 uint64 `json:"p90"`
|
|
P95 uint64 `json:"p95"`
|
|
P99 uint64 `json:"p99"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type RequestMetricReadable struct {
|
|
Duration DurationMetricReadable `json:"duration"`
|
|
Count CounterMetric `json:"count"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type RequestMetric struct {
|
|
Duration DurationMetric `json:"duration"`
|
|
Count CounterMetric `json:"count"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type RuntimeMetric struct {
|
|
GoVersion string `json:"go_version"`
|
|
GoOs string `json:"go_os"`
|
|
GoArch string `json:"go_arch"`
|
|
CpuNum int `json:"cpu_num"`
|
|
GoroutineNum int `json:"goroutine_num"`
|
|
Gomaxprocs int `json:"go_maxprocs"`
|
|
CgoCallNum int64 `json:"cgo_call_num"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type MemoryMetric struct {
|
|
MemAllocated uint64 `json:"mem_allocated"`
|
|
MemTotal uint64 `json:"mem_total"`
|
|
MemSys uint64 `json:"mem_sys"`
|
|
Lookups uint64 `json:"lookups"`
|
|
MemMallocs uint64 `json:"mem_mallocs"`
|
|
MemFrees uint64 `json:"mem_frees"`
|
|
|
|
HeapAlloc uint64 `json:"heap_alloc"`
|
|
HeapSys uint64 `json:"heap_sys"`
|
|
HeapIdle uint64 `json:"heap_idle"`
|
|
HeapInuse uint64 `json:"heap_inuse"`
|
|
HeapReleased uint64 `json:"heap_released"`
|
|
HeapObjects uint64 `json:"heap_objects"`
|
|
|
|
StackInuse uint64 `json:"stack_inuse"`
|
|
StackSys uint64 `json:"stack_sys"`
|
|
MSpanInuse uint64 `json:"m_span_inuse"`
|
|
MSpanSys uint64 `json:"m_span_sys"`
|
|
MCacheInuse uint64 `json:"m_cache_inuse"`
|
|
MCacheSys uint64 `json:"m_cache_sys"`
|
|
BuckHashSys uint64 `json:"buck_hash_sys"`
|
|
GCSys uint64 `json:"gc_sys"`
|
|
OtherSys uint64 `json:"other_sys"`
|
|
|
|
NextGC uint64 `json:"next_gc"`
|
|
LastGC uint64 `json:"last_gc"`
|
|
PauseTotalNs uint64 `json:"pause_total_ns"`
|
|
PauseNs uint64 `json:"pause_ns"`
|
|
NumGC uint32 `json:"num_gc"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type Metric struct {
|
|
Cmdline []string `json:"cmd_line"`
|
|
Uptime uint64 `json:"uptime"`
|
|
Request RequestMetric `json:"request"`
|
|
Runtime RuntimeMetric `json:"runtime"`
|
|
Memory MemoryMetric `json:"memory"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type PermRes struct {
|
|
code int `json:"-" binding:"required"`
|
|
Message string `json:"message" binding:"required"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type MemoryMetricReadable struct {
|
|
MemAllocated string `json:"mem_allocated"`
|
|
MemTotal string `json:"mem_total"`
|
|
MemSys string `json:"mem_sys"`
|
|
Lookups uint64 `json:"lookups"`
|
|
MemMallocs uint64 `json:"mem_mallocs"`
|
|
MemFrees uint64 `json:"mem_frees"`
|
|
|
|
HeapAlloc string `json:"heap_alloc"`
|
|
HeapSys string `json:"heap_sys"`
|
|
HeapIdle string `json:"heap_idle"`
|
|
HeapInuse string `json:"heap_inuse"`
|
|
HeapReleased string `json:"heap_released"`
|
|
HeapObjects uint64 `json:"heap_objects"`
|
|
|
|
StackInuse string `json:"stack_inuse"`
|
|
StackSys string `json:"stack_sys"`
|
|
MSpanInuse string `json:"m_span_inuse"`
|
|
MSpanSys string `json:"m_span_sys"`
|
|
MCacheInuse string `json:"m_cache_inuse"`
|
|
MCacheSys string `json:"m_cache_sys"`
|
|
BuckHashSys string `json:"buck_hash_sys"`
|
|
GCSys string `json:"gc_sys"`
|
|
OtherSys string `json:"other_sys"`
|
|
|
|
NextGC string `json:"next_gc"`
|
|
LastGC string `json:"last_gc"`
|
|
PauseTotalNs string `json:"pause_total_ns"`
|
|
PauseNs string `json:"pause_ns"`
|
|
NumGC uint32 `json:"num_gc"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type MetricReadable struct {
|
|
Cmdline []string `json:"cmd_line"`
|
|
Uptime string `json:"uptime"`
|
|
Request RequestMetricReadable `json:"request"`
|
|
Runtime RuntimeMetric `json:"runtime"`
|
|
Memory MemoryMetricReadable `json:"memory"`
|
|
}
|
|
|
|
//easyjson:json
|
|
type UserData struct {
|
|
Id string `json:"id" binding:"required"`
|
|
Name string `json:"name" binding:"required"`
|
|
Mail string `json:"mail" binding:"required"`
|
|
Role enums.UserType `json:"role" binding:"required"`
|
|
}
|
|
|
|
func (detail *UserData) String() string {
|
|
var buffer bytes.Buffer
|
|
buffer.WriteString("UserData(")
|
|
if detail != nil {
|
|
buffer.WriteString("id:")
|
|
buffer.WriteString(detail.Id)
|
|
} else {
|
|
buffer.WriteString("nil")
|
|
}
|
|
buffer.WriteString(")")
|
|
return buffer.String()
|
|
}
|
|
|
|
// -vars="mem:memory.mem_allocated,duration:request.duration.min,duration:request.duration.max,duration:request.duration.mean,duration:request.duration.stdev,duration:request.duration.p90,duration:request.duration.p95,duration:request.duration.p99,mem:memory.mem_allocated,mem:memory.heap_alloc,mem:memory.heap_inuse,mem:memory.stack_inuse,duration:memory.next_gc,duration:memory.last_gc,duration:memory.pause_total_ns,duration:memory.pause_ns"
|