-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuse-r-main-context.go
94 lines (74 loc) · 1.76 KB
/
fuse-r-main-context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2024.
* Created by Andy Pangaribuan <https://github.com/apangaribuan>.
*
* This product is protected by copyright and distributed under
* licenses restricting copying, distribution and decompilation.
* All Rights Reserved.
*/
package server
import (
"fmt"
"github.com/andypangaribuan/gmod/fm"
)
func (slf *stuFuseRMainContext) regulator() *stuFuseRRegulator {
return &stuFuseRRegulator{
mcx: slf,
currentIndex: -1,
}
}
func (slf *stuFuseRMainContext) severity() string {
if slf.val.unrouted {
return "unrouted"
}
severity := "unknown"
switch {
case slf.responseMeta.Code >= 100 && slf.responseMeta.Code <= 199:
severity = "server"
case slf.responseMeta.Code >= 200 && slf.responseMeta.Code <= 299:
severity = "success"
case slf.responseMeta.Code >= 300 && slf.responseMeta.Code <= 399:
severity = "server"
case slf.responseMeta.Code >= 400 && slf.responseMeta.Code <= 499:
severity = "warning"
case slf.responseMeta.Code >= 500 && slf.responseMeta.Code <= 599:
severity = "error"
}
return severity
}
func (slf *stuFuseRMainContext) getUserId() *string {
return slf.idCast(slf.userId)
}
func (slf *stuFuseRMainContext) getPartnerId() *string {
return slf.idCast(slf.partnerId)
}
func (slf *stuFuseRMainContext) idCast(id any) *string {
if id == nil {
return nil
}
switch val := id.(type) {
case string:
return &val
case *string:
return val
case int:
return fm.Ptr(fmt.Sprint(val))
case *int:
if val != nil {
return fm.Ptr(fmt.Sprint(*val))
}
case int32:
return fm.Ptr(fmt.Sprint(val))
case *int32:
if val != nil {
return fm.Ptr(fmt.Sprint(*val))
}
case int64:
return fm.Ptr(fmt.Sprint(val))
case *int64:
if val != nil {
return fm.Ptr(fmt.Sprint(*val))
}
}
return nil
}