Skip to content

Commit 0531e66

Browse files
committed
Add common testing system initialization
1 parent c072cef commit 0531e66

File tree

8 files changed

+337
-9
lines changed

8 files changed

+337
-9
lines changed

go.mod

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,47 @@ go 1.22
55
toolchain go1.22rc1
66

77
require (
8+
github.com/gin-gonic/gin v1.10.0
89
github.com/lib/pq v1.10.9
10+
github.com/xorcare/pointer v1.2.2
11+
gopkg.in/yaml.v3 v3.0.1
912
gorm.io/driver/postgres v1.5.9
1013
gorm.io/gorm v1.25.12
1114
)
1215

1316
require (
17+
github.com/bytedance/sonic v1.11.6 // indirect
18+
github.com/bytedance/sonic/loader v0.1.1 // indirect
19+
github.com/cloudwego/base64x v0.1.4 // indirect
20+
github.com/cloudwego/iasm v0.2.0 // indirect
21+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
22+
github.com/gin-contrib/sse v0.1.0 // indirect
23+
github.com/go-playground/locales v0.14.1 // indirect
24+
github.com/go-playground/universal-translator v0.18.1 // indirect
25+
github.com/go-playground/validator/v10 v10.20.0 // indirect
26+
github.com/goccy/go-json v0.10.2 // indirect
1427
github.com/jackc/pgpassfile v1.0.0 // indirect
1528
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
1629
github.com/jackc/pgx/v5 v5.5.5 // indirect
1730
github.com/jackc/puddle/v2 v2.2.1 // indirect
1831
github.com/jinzhu/inflection v1.0.0 // indirect
1932
github.com/jinzhu/now v1.1.5 // indirect
20-
golang.org/x/crypto v0.17.0 // indirect
33+
github.com/json-iterator/go v1.1.12 // indirect
34+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
35+
github.com/kr/text v0.2.0 // indirect
36+
github.com/leodido/go-urn v1.4.0 // indirect
37+
github.com/mattn/go-isatty v0.0.20 // indirect
38+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
39+
github.com/modern-go/reflect2 v1.0.2 // indirect
40+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
41+
github.com/rogpeppe/go-internal v1.13.1 // indirect
42+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
43+
github.com/ugorji/go/codec v1.2.12 // indirect
44+
golang.org/x/arch v0.8.0 // indirect
45+
golang.org/x/crypto v0.23.0 // indirect
46+
golang.org/x/net v0.25.0 // indirect
2147
golang.org/x/sync v0.1.0 // indirect
22-
golang.org/x/text v0.14.0 // indirect
48+
golang.org/x/sys v0.21.0 // indirect
49+
golang.org/x/text v0.15.0 // indirect
50+
google.golang.org/protobuf v1.34.1 // indirect
2351
)

go.sum

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1+
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
2+
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
3+
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
4+
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
5+
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
6+
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
7+
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
8+
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
9+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
110
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
211
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
312
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
14+
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
15+
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
16+
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
17+
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
18+
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
19+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
20+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
21+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
22+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
23+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
24+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
25+
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
26+
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
27+
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
28+
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
29+
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
30+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
31+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
432
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
533
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
634
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
@@ -13,26 +41,79 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
1341
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
1442
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
1543
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
44+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
45+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
46+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
47+
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
48+
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
49+
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
50+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
51+
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
52+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
53+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
54+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
55+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
1656
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
1757
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
58+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
59+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
60+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
61+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
62+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
63+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
64+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
65+
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
66+
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
1867
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1968
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
69+
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
70+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
2071
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
72+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
73+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
74+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
2175
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2276
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
23-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
77+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
78+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
2479
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
25-
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
26-
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
80+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
81+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
82+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
83+
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
84+
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
85+
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
86+
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
87+
github.com/xorcare/pointer v1.2.2 h1:zjD77b5DTehClND4MK+9dDE0DcpFIZisAJ/+yVJvKYA=
88+
github.com/xorcare/pointer v1.2.2/go.mod h1:azsKh7oVwYB7C1o8P284fG8MvtErX/F5/dqXiaj71ak=
89+
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
90+
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
91+
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
92+
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
93+
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
94+
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
95+
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
2796
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
2897
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
29-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
30-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
98+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
99+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
100+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
101+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
102+
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
103+
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
104+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
105+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
106+
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
107+
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
31108
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
109+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
110+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
32111
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
33112
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
34113
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
35114
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
36115
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
37116
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
38117
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
118+
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
119+
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

lib/common/testing_system.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package common
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"strconv"
6+
"testing_system/lib/config"
7+
"testing_system/lib/logger"
8+
)
9+
10+
type TestingSystem struct {
11+
Config *config.Config
12+
Router *gin.Engine
13+
// TODO: Add common params for all testing system components
14+
}
15+
16+
func InitTestingSystem(configPath string) *TestingSystem {
17+
ts := &TestingSystem{
18+
Config: config.ReadConfig(configPath),
19+
}
20+
logger.InitLogger(ts.Config)
21+
ts.Router = gin.Default() // TODO: Add router options (e.g debug)
22+
23+
// TODO: Add all TestingSystem common components initialization
24+
25+
return ts
26+
}
27+
28+
func (ts *TestingSystem) Run() {
29+
addr := ":" + strconv.Itoa(ts.Config.Port)
30+
if ts.Config.Host != nil {
31+
addr = *ts.Config.Host + addr
32+
}
33+
logger.Info("Starting server at " + addr)
34+
err := ts.Router.Run(addr)
35+
if err != nil {
36+
logger.Panic(err.Error())
37+
}
38+
}

lib/config/config.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package config
2+
3+
import (
4+
"os"
5+
6+
"github.com/xorcare/pointer"
7+
"gopkg.in/yaml.v3"
8+
)
9+
10+
type Config struct {
11+
Port int `yaml:"Port"`
12+
Host *string `yaml:"Host,omitempty"` // leave empty for localhost
13+
14+
LogPath *string `yaml:"LogPath,omitempty"`
15+
LogLevel *int `yaml:"LogLevel,omitempty"`
16+
17+
// TODO: Add all components here
18+
19+
// if instance is set up on server, leave connection empty
20+
MasterConnection *Connection `yaml:"MasterConnection,omitempty"`
21+
StorageConnection *Connection `yaml:"StorageConnection,omitempty"`
22+
}
23+
24+
func ReadConfig(configPath string) *Config {
25+
content, err := os.ReadFile(configPath)
26+
if err != nil {
27+
panic(err)
28+
}
29+
30+
config := new(Config)
31+
err = yaml.Unmarshal(content, config)
32+
if err != nil {
33+
panic(err)
34+
}
35+
36+
fillInConfig(config)
37+
38+
return config
39+
}
40+
41+
func fillInConfig(config *Config) {
42+
if config.Host == nil {
43+
config.Host = pointer.String("localhost")
44+
}
45+
46+
fillInConnections(config)
47+
}

lib/config/connection.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package config
2+
3+
type Connection struct {
4+
Address string `yaml:"Address"`
5+
// TODO: Add authentification
6+
}
7+
8+
func fillInConnections(config *Config) {
9+
// TODO: Add auto connection creation if master or storage are set up
10+
}

lib/logger/logger.go

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
11
package logger
22

3-
func Panic(format string, v ...interface{}) {
4-
// TODO: create logger
3+
import (
4+
"fmt"
5+
base_log "log"
6+
"os"
7+
"testing_system/lib/config"
8+
)
9+
10+
const (
11+
LOG_LEVEL_TRACE = 0
12+
LOG_LEVEL_DEBUG = 1
13+
LOG_LEVEL_INFO = 2
14+
LOG_LEVEL_WARN = 3
15+
LOG_LEVEL_ERROR = 4
16+
)
17+
18+
var (
19+
logLevel = LOG_LEVEL_DEBUG
20+
log = base_log.New(os.Stdout, "", base_log.Ldate|base_log.Ltime)
21+
logErr = base_log.New(os.Stderr, "", base_log.Ldate|base_log.Ltime)
22+
)
23+
24+
func Trace(format string, values ...interface{}) {
25+
logPrint(LOG_LEVEL_TRACE, format, values...)
26+
}
27+
28+
func Debug(format string, values ...any) {
29+
logPrint(LOG_LEVEL_DEBUG, format, values...)
30+
}
31+
32+
func Info(format string, values ...any) {
33+
logPrint(LOG_LEVEL_INFO, format, values...)
34+
}
35+
36+
func Warn(format string, values ...any) {
37+
logPrint(LOG_LEVEL_WARN, format, values...)
38+
}
39+
40+
func Error(format string, values ...any) error {
41+
logPrint(LOG_LEVEL_ERROR, format, values...)
42+
logErr.Printf(logErrPrefix()+format, values...)
43+
return fmt.Errorf(format, values...)
44+
}
45+
46+
func Panic(format string, value ...any) {
47+
logPrint(LOG_LEVEL_ERROR, format, value...)
48+
logErr.Panicf(format, value...)
49+
}
50+
51+
func InitLogger(config *config.Config) {
52+
logLevel = LOG_LEVEL_INFO
53+
if config.LogLevel != nil {
54+
logLevel = *config.LogLevel
55+
}
56+
57+
var logFile, logErrFile *os.File
58+
59+
if config.LogPath == nil {
60+
logFile = os.Stdout
61+
logErrFile = os.Stderr
62+
} else {
63+
var err error
64+
logFile, err = os.OpenFile(*config.LogPath+".log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0660)
65+
if err != nil {
66+
panic(err)
67+
}
68+
69+
logErrFile, err = os.OpenFile(*config.LogPath+".err", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0660)
70+
if err != nil {
71+
panic(err)
72+
}
73+
}
74+
75+
flags := base_log.Ldate | base_log.Ltime
76+
log = base_log.New(logFile, "", flags)
77+
logErr = base_log.New(logErrFile, "", flags)
78+
79+
Info("Logger is successfully initialized")
580
}

lib/logger/utils.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package logger
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
7+
8+
func levelString(level int) string {
9+
switch level {
10+
case LOG_LEVEL_DEBUG:
11+
return "[DEBUG]"
12+
case LOG_LEVEL_INFO:
13+
return "[INFO]"
14+
case LOG_LEVEL_WARN:
15+
return "[WARN]"
16+
case LOG_LEVEL_ERROR:
17+
return "[ERROR]"
18+
default:
19+
return ""
20+
}
21+
}
22+
23+
func logPrint(level int, format string, value ...any) {
24+
if logLevel <= level {
25+
log.Printf(levelString(level)+" "+format, value...)
26+
}
27+
}
28+
29+
func logErrPrefix() string {
30+
_, file, line, ok := runtime.Caller(2)
31+
if ok {
32+
return fmt.Sprintf("%s:%d ", file, line)
33+
} else {
34+
return ""
35+
}
36+
}

0 commit comments

Comments
 (0)