正在显示
124 个修改的文件
包含
3973 行增加
和
0 行删除
.gitignore
0 → 100644
1 | +# Compiled Object codefiles, Static and Dynamic libs (Shared Objects) | ||
2 | +*.o | ||
3 | +*.a | ||
4 | +*.so | ||
5 | + | ||
6 | +# Folders | ||
7 | +_obj | ||
8 | +_test | ||
9 | + | ||
10 | +# Architecture specific extensions/prefixes | ||
11 | +*.[568vq] | ||
12 | +[568vq].out | ||
13 | + | ||
14 | +*.cgo1.go | ||
15 | +*.cgo2.c | ||
16 | +_cgo_defun.c | ||
17 | +_cgo_gotypes.go | ||
18 | +_cgo_export.* | ||
19 | + | ||
20 | +_testmain.go | ||
21 | + | ||
22 | +*.exe | ||
23 | +*.test | ||
24 | +.log | ||
25 | +.idea | ||
26 | + | ||
27 | +app.log | ||
28 | +go.sum | ||
29 | +lastupdate.tmp |
Dockerfile
0 → 100644
1 | +FROM golang:latest | ||
2 | +ENV APP_DIR $GOPATH/src/character-library-metadata-bastion | ||
3 | +RUN mkdir -p $APP_DIR | ||
4 | +WORKDIR $APP_DIR/ | ||
5 | +COPY ./pkg pkg | ||
6 | +COPY ./conf conf | ||
7 | +COPY ./go.mod go.mod | ||
8 | +COPY ./go.sum go.sum | ||
9 | +COPY ./main.go main.go | ||
10 | +RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"] | ||
11 | +ENV GO111MODULE on | ||
12 | +ENV GOPROXY https://goproxy.io | ||
13 | +RUN ["go","mod","tidy"] | ||
14 | +RUN ["ls"] | ||
15 | +RUN ["go","build"] | ||
16 | +ENTRYPOINT ["./character-library-metadata-bastion"] |
README.md
0 → 100644
config/app.conf
0 → 100644
1 | +POSTGRESQL_DB_NAME = allied_creation_dev | ||
2 | +POSTGRESQL_HOST = 114.55.200.59 | ||
3 | +POSTGRESQL_PORT = 31543 | ||
4 | +POSTGRESQL_USER = postgres | ||
5 | +POSTGRESQL_PASSWORD = eagle1010 | ||
6 | +DISABLE_SQL_GENERATE_COMMENT = false | ||
7 | +SERVICE_ENV = test | ||
8 | +HTTP_PORT = 8081 | ||
9 | +ENABLE_KAFKA_LOG11 = true | ||
10 | +HTTPS_PORT = 8143 | ||
11 | +ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com |
config/app_test.conf
0 → 100644
1 | +POSTGRESQL_DB_NAME = allied_creation_test | ||
2 | +POSTGRESQL_HOST = 114.55.200.59 | ||
3 | +POSTGRESQL_PORT = 31543 | ||
4 | +POSTGRESQL_USER = postgres | ||
5 | +POSTGRESQL_PASSWORD = eagle1010 | ||
6 | +DISABLE_SQL_GENERATE_COMMENT = false | ||
7 | +SERVICE_ENV = test | ||
8 | +HTTP_PORT = 8081 | ||
9 | +ENABLE_KAFKA_LOG11 = true | ||
10 | +HTTPS_PORT = 8143 | ||
11 | +ALLIED_CREATION_USER_HOST = http://allied-creation-user-test.fjmaimaimai.com | ||
12 | +MANUFACTURE_DEFAULT_COMPANYID = 23 | ||
13 | +MANUFACTURE_DEFAULT_ORGID = 487 | ||
14 | +MANUFACTURE_DEFAULT_WORKSHOPID = 28 |
config/fjmaimaimai.com.key
0 → 100644
1 | +-----BEGIN RSA PRIVATE KEY----- | ||
2 | +MIIEpAIBAAKCAQEA45R02HLq/QHraf7VBf6QO4ca1StnmvztF5BLVU7txhKe9FD4 | ||
3 | +CLUhwharlUlPPjYFdqm9pFxynUqt15djEPhGVUEFeBpf931pVuPugNmZ/AVj0p8y | ||
4 | +06eTNLphkrzCdBzISUN5E3PKglz3efIzq6ZK8vbns/XSQA9NRzAPTboe0KC0Flj4 | ||
5 | +YPP1X69aJiBOGClsAjG1EXQ6gxepBiL1Fq3GtpKHrQPFHffUXEkPZJz09x6RxpuU | ||
6 | +CrtxUKdO6eKg89COo3xLXVpOZu94+csBAgvXqmADp/XCQELZRMTTEA4OIyz7yXoK | ||
7 | +nmqceoHaeSv4nzDDMwzITFvWmZHDPHLuZwNSZwIDAQABAoIBAQDGPKf3b0rQLt7g | ||
8 | +irEGsrLyl4JBE7kA4bao4vEsEz+9XLUHfoxAEX+hcFvwA1a6ixYBQmRGCp1v9AAw | ||
9 | +HteVjZ6+XpAkCV102NJsdMlphaLDS/KjIjeE9KCeuoeJ6VC9EeFJKDQMRL2vBsov | ||
10 | +eFGYAJeiwn4cXVHSqUGYc/2wqCJ1eRHJkvprDqIeZU8ND3uQ5Gz/5azezf8hBu2P | ||
11 | +MUDseX1PzdvvElidxpHR1KsZTvGVFMMFWRcSDfQYSIB8EevMKQS2YwU9kmiCI3s3 | ||
12 | +qDEAc/Usj64oRLh3Wwh9V0H26zpn/XyQ5pzYmWtCGUpifGuAAQeFKc1jPN6fJy6a | ||
13 | +WwLprqV5AoGBAP0k7btOXE5+hmMGcuiu3vWg0X3EOQf7MtMlsrMbqrzS4HbaaMqP | ||
14 | +BW4hrQOLl8zB9vOYt0TuK0/+ONLlCgYiodqA8FkC7TUHcTyHUEIE3+QTrI23CY6z | ||
15 | +AbJgnHew4jKhRvbLFHkrrIMWgRIDlIwk7HFwHLpU9tw2SsHMz6hWQjY1AoGBAOYl | ||
16 | +suq/hyYHlI6ggbzkFjchlRxBFEOm8GOa6LLjuP0sxbaFXXfFUtw4YhO0WL8X9JSm | ||
17 | +Qtsb4HVQPZMGlrY5rale4FOXBnSovt0LuPR3gX9OaK9T9x4X+gabQrlGIlcS2QRM | ||
18 | +AvwPGlWptLLmQOgWdcZ5xOGEWdXDhIFrAK6khEmrAoGBAJDRM39YEM6G63JzGgGr | ||
19 | +KLn0SmRcgRPjzOumQVjdlwt2yBq2UASxVTXv5f6FOU5WGGS7FP1GE1kr4m4jwVxJ | ||
20 | +K7bI1LbXScRwgYNTFcLu7vaXmrtn3vvXxDy7sEd41a6JPQOqoge/yG0lzqjzi2Ox | ||
21 | +K+KpdIXUXXUVSicceB+hWTeRAoGAIVuXejT2hsmUe7PB+jnpCmagsS6xnDinIRjD | ||
22 | +36HoHzINGi5sZL7CCs9VT9vU/SWguqb6i72XpAlUU2oiEBl+FU1+ID+EnQYUW/+l | ||
23 | ++DEWIPihbcAy0jbRc4GvgyEqOwqtT9UgnZ4myAHIAiIjiEAxI+pkYfeH+dbT7tou | ||
24 | +iCGqVu8CgYBOF/1Ek3ex23CryLuMHg8wp0VHSSuksnurMWkg/H8qBT7NjWhVNRCi | ||
25 | +mrjy2oCSI6TKPwVZQo15LeOuhXkfYFig667sBvo59Nz+QBQhh6NGwrSiZuYlf3F/ | ||
26 | +8mgDIjspJm4R9kFRAZZcsuHH6hHAge5Lik/yRyztxI9Vlpok6e1bEw== | ||
27 | +-----END RSA PRIVATE KEY----- |
config/fjmaimaimai.com_bundle.crt
0 → 100644
1 | +-----BEGIN CERTIFICATE----- | ||
2 | +MIIGeTCCBWGgAwIBAgIRAI8zZs95ViIzW/6yB+17fngwDQYJKoZIhvcNAQELBQAw | ||
3 | +XDELMAkGA1UEBhMCQ04xGjAYBgNVBAoTEVdvVHJ1cyBDQSBMaW1pdGVkMTEwLwYD | ||
4 | +VQQDDChXb1RydXMgT1YgU2VydmVyIENBICBbUnVuIGJ5IHRoZSBJc3N1ZXJdMB4X | ||
5 | +DTIyMDIxMDAwMDAwMFoXDTIzMDMxMjIzNTk1OVowZjELMAkGA1UEBhMCQ04xEjAQ | ||
6 | +BgNVBAgMCeemj+W7uuecgTEnMCUGA1UECgwe5aSp6IGU5L+h5oGv56eR5oqA5pyJ | ||
7 | +6ZmQ5YWs5Y+4MRowGAYDVQQDDBEqLmZqbWFpbWFpbWFpLmNvbTCCASIwDQYJKoZI | ||
8 | +hvcNAQEBBQADggEPADCCAQoCggEBAOOUdNhy6v0B62n+1QX+kDuHGtUrZ5r87ReQ | ||
9 | +S1VO7cYSnvRQ+Ai1IcIWq5VJTz42BXapvaRccp1KrdeXYxD4RlVBBXgaX/d9aVbj | ||
10 | +7oDZmfwFY9KfMtOnkzS6YZK8wnQcyElDeRNzyoJc93nyM6umSvL257P10kAPTUcw | ||
11 | +D026HtCgtBZY+GDz9V+vWiYgThgpbAIxtRF0OoMXqQYi9RatxraSh60DxR331FxJ | ||
12 | +D2Sc9PcekcablAq7cVCnTunioPPQjqN8S11aTmbvePnLAQIL16pgA6f1wkBC2UTE | ||
13 | +0xAODiMs+8l6Cp5qnHqB2nkr+J8wwzMMyExb1pmRwzxy7mcDUmcCAwEAAaOCAyow | ||
14 | +ggMmMB8GA1UdIwQYMBaAFA1JjxUze8BPtvs6OAn8NBXaYN0UMB0GA1UdDgQWBBSd | ||
15 | +7Jpt75ZS1gDF9uvt6jq/wsM6pTAOBgNVHQ8BAf8EBAMCBaAwDAYDVR0TAQH/BAIw | ||
16 | +ADAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwSQYDVR0gBEIwQDA0Bgsr | ||
17 | +BgEEAbIxAQICFjAlMCMGCCsGAQUFBwIBFhdodHRwczovL3NlY3RpZ28uY29tL0NQ | ||
18 | +UzAIBgZngQwBAgIwPQYDVR0fBDYwNDAyoDCgLoYsaHR0cDovL2NybC5jcmxvY3Nw | ||
19 | +LmNuL1dvVHJ1c09WU2VydmVyQ0FfMi5jcmwwbAYIKwYBBQUHAQEEYDBeMDgGCCsG | ||
20 | +AQUFBzAChixodHRwOi8vYWlhLmNybG9jc3AuY24vV29UcnVzT1ZTZXJ2ZXJDQV8y | ||
21 | +LmNydDAiBggrBgEFBQcwAYYWaHR0cDovL29jc3AuY3Jsb2NzcC5jbjCCAX4GCisG | ||
22 | +AQQB1nkCBAIEggFuBIIBagFoAHYArfe++nz/EMiLnT2cHj4YarRnKV3PsQwkyoWG | ||
23 | +NOvcgooAAAF+4S03XgAABAMARzBFAiEAqR1sq52hM4f5aS3cvFX0eMSDkBy0Ezbf | ||
24 | +8O6DPg7404sCIC+acfUKRvt4A89tcgvdK8TiAvFb1zaaN5608wtyLUcRAHcAejKM | ||
25 | +VNi3LbYg6jjgUh7phBZwMhOFTTvSK8E6V6NS61IAAAF+4S03HAAABAMASDBGAiEA | ||
26 | +7OiNg/IGkzMm3/NDw+oZuqDAYgigaq9Bsh67gyRDw9oCIQCexK1Oo74f6IMRebPU | ||
27 | +Z2/U6DyiOh6bUu/qJJyyhjBHrgB1AOg+0No+9QY1MudXKLyJa8kD08vREWvs62nh | ||
28 | +d31tBr1uAAABfuEtNwMAAAQDAEYwRAIgWcr/D/Ygi5WOeoRdpg93smwz6snU9vxL | ||
29 | +I0CLiufIfKECIAFvFv9PMrHTyC05TIGfWfkVHqGZoPjPKRUtZyoWlMGaMC0GA1Ud | ||
30 | +EQQmMCSCESouZmptYWltYWltYWkuY29tgg9mam1haW1haW1haS5jb20wDQYJKoZI | ||
31 | +hvcNAQELBQADggEBAHhfZLmBvIDl9kQvKZf2IrFUNbd9/yLWnrCoKOaQejVVOGkZ | ||
32 | +BmFpn2ZXGCfuCZUqhZQLc9xL49fkmBACQJa358pLUcrMRweZPPRPW53uGWH6N3IA | ||
33 | +cAShUscFU9LBZ7ynbK9OG58E1O9/taJVQGd7YmjhEyA7A3oTtxjedk1ZPz1Hue/w | ||
34 | +au5wfAg9Tl4ds8/rPTCACSYTd1HXhR9OuqDcinTdtwJrzKp3NKWpQjPvgpNcaJPA | ||
35 | +j8JHnggP3GDe4xGNyt6CmNuZpWVm23CT7pFYwqQYTLqKB5yFRK4PUZ3PPKz49gQv | ||
36 | +hkln6/8l93Jt5oRolk4kq6A/D64jwlNwa7EPlz8= | ||
37 | +-----END CERTIFICATE----- | ||
38 | +-----BEGIN CERTIFICATE----- | ||
39 | +MIIF4TCCA8mgAwIBAgIQHQgpVDhMv3SvabmRFpvwLTANBgkqhkiG9w0BAQwFADCB | ||
40 | +iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl | ||
41 | +cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV | ||
42 | +BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMjAw | ||
43 | +MTA4MDAwMDAwWhcNMzAwMTA3MjM1OTU5WjBcMQswCQYDVQQGEwJDTjEaMBgGA1UE | ||
44 | +ChMRV29UcnVzIENBIExpbWl0ZWQxMTAvBgNVBAMMKFdvVHJ1cyBPViBTZXJ2ZXIg | ||
45 | +Q0EgIFtSdW4gYnkgdGhlIElzc3Vlcl0wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw | ||
46 | +ggEKAoIBAQCARFLq6kqQRZ4SdFMPdd3XJTcOdVVT5bvZZx0VVDrkw3TmSAloQVFf | ||
47 | +RhqDOSXg4CsIaa64qFSrC3a5sc8LgRhx7AUdvoUdfvdxIY1uoyxRWpoWO8oTUkSn | ||
48 | +EXjEPf+zrcU5cWTOi32xWL9vklYds7iOQwgsKAHDzt4an8MLGvcLxAHciyiKcDEh | ||
49 | +HZOGUHO5bKaCq+kP2rJCfVSlNvdyl1B8q+aGWXoi0gXGVL7WX4pcWj+DGuITbLB2 | ||
50 | +MzMytse4MjLJ84zaXh0UD4STlyD8tu/fakdxIwQ7K3/pP3RoGj1R9CvMWXUU+fZm | ||
51 | +KNLW5565hd9Bh3Wkz8b4ApgMD9o3RUjTAgMBAAGjggFwMIIBbDAfBgNVHSMEGDAW | ||
52 | +gBRTeb9aqitKz1SA4dibwJ3ysgNmyzAdBgNVHQ4EFgQUDUmPFTN7wE+2+zo4Cfw0 | ||
53 | +Fdpg3RQwDgYDVR0PAQH/BAQDAgGGMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0l | ||
54 | +BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMCIGA1UdIAQbMBkwDQYLKwYBBAGyMQEC | ||
55 | +AhYwCAYGZ4EMAQICMFAGA1UdHwRJMEcwRaBDoEGGP2h0dHA6Ly9jcmwudXNlcnRy | ||
56 | +dXN0LmNvbS9VU0VSVHJ1c3RSU0FDZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNybDBx | ||
57 | +BggrBgEFBQcBAQRlMGMwOgYIKwYBBQUHMAKGLmh0dHA6Ly9jcnQudXNlcnRydXN0 | ||
58 | +LmNvbS9VU0VSVHJ1c3RSU0FBQUFDQS5jcnQwJQYIKwYBBQUHMAGGGWh0dHA6Ly9v | ||
59 | +Y3NwLnVzZXJ0cnVzdC5jb20wDQYJKoZIhvcNAQEMBQADggIBAA5G7XA+fNKyj7Fy | ||
60 | +uotoII38/32eZ4UrC1vGFPEtDyd0yzOrr7SvQUoO2GLxFzIQ0SsgMNXJ4UAhMkTD | ||
61 | +yz1OA0tx0g0GjOQXBGA/yfRR7SgitRJAdbqkPfppMn+dtKXCHHx35ohTL0PklRdb | ||
62 | +mXacvR7rXUIiJMdsvZZqYwc+DpGJ+Zv0sRJZEL7pm1oZv6EV+UzjAlOnLe6yrnyD | ||
63 | +c99Kk1H/RFPUzduUWjiVR2aMDT1oMiwYeB2Zq60Sb201jqZPNQj5E+TkDD5BPFVc | ||
64 | +kLeRi3LyXBUuBvXPsdLtBNlr+LExtCDd66kjeUe2/YbTHF4ai5PZPraQxgbOJJyc | ||
65 | +gizGl/JOgrIQPUOLSQvXlxpKEqS+0z6KqV52bco2PNrC0f8ILKuw0nsfhgcGy46d | ||
66 | +Su8fmU9+FT6e61i2nteKvt8qkkSkAJKQxRUWYduN24mG/OOIkoeOPdYHi+qEfbyI | ||
67 | +qxiiqcH9cZgLK9AVuJoKtt7vg21OyrWi7S5T/WbTfTz9XL7QGe8ZODZZx6d50uo/ | ||
68 | +lDOmXm3p/kdGApvUF1UrL+og22jBLi0Ns6xzCfzrI3SpC9abvU8E9EnxQABuu/gM | ||
69 | +/B63dbaZzSsMVFxeECD9nMWv7IH+/rqyGmjqEJzgKdPGvXhqpebQ1HhWrV+j+ipc | ||
70 | +jplXB1j3GCozDFsninXG102N6wC8 | ||
71 | +-----END CERTIFICATE----- | ||
72 | +-----BEGIN CERTIFICATE----- | ||
73 | +MIIFgTCCBGmgAwIBAgIQOXJEOvkit1HX02wQ3TE1lTANBgkqhkiG9w0BAQwFADB7 | ||
74 | +MQswCQYDVQQGEwJHQjEbMBkGA1UECAwSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYD | ||
75 | +VQQHDAdTYWxmb3JkMRowGAYDVQQKDBFDb21vZG8gQ0EgTGltaXRlZDEhMB8GA1UE | ||
76 | +AwwYQUFBIENlcnRpZmljYXRlIFNlcnZpY2VzMB4XDTE5MDMxMjAwMDAwMFoXDTI4 | ||
77 | +MTIzMTIzNTk1OVowgYgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpOZXcgSmVyc2V5 | ||
78 | +MRQwEgYDVQQHEwtKZXJzZXkgQ2l0eTEeMBwGA1UEChMVVGhlIFVTRVJUUlVTVCBO | ||
79 | +ZXR3b3JrMS4wLAYDVQQDEyVVU0VSVHJ1c3QgUlNBIENlcnRpZmljYXRpb24gQXV0 | ||
80 | +aG9yaXR5MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAgBJlFzYOw9sI | ||
81 | +s9CsVw127c0n00ytUINh4qogTQktZAnczomfzD2p7PbPwdzx07HWezcoEStH2jnG | ||
82 | +vDoZtF+mvX2do2NCtnbyqTsrkfjib9DsFiCQCT7i6HTJGLSR1GJk23+jBvGIGGqQ | ||
83 | +Ijy8/hPwhxR79uQfjtTkUcYRZ0YIUcuGFFQ/vDP+fmyc/xadGL1RjjWmp2bIcmfb | ||
84 | +IWax1Jt4A8BQOujM8Ny8nkz+rwWWNR9XWrf/zvk9tyy29lTdyOcSOk2uTIq3XJq0 | ||
85 | +tyA9yn8iNK5+O2hmAUTnAU5GU5szYPeUvlM3kHND8zLDU+/bqv50TmnHa4xgk97E | ||
86 | +xwzf4TKuzJM7UXiVZ4vuPVb+DNBpDxsP8yUmazNt925H+nND5X4OpWaxKXwyhGNV | ||
87 | +icQNwZNUMBkTrNN9N6frXTpsNVzbQdcS2qlJC9/YgIoJk2KOtWbPJYjNhLixP6Q5 | ||
88 | +D9kCnusSTJV882sFqV4Wg8y4Z+LoE53MW4LTTLPtW//e5XOsIzstAL81VXQJSdhJ | ||
89 | +WBp/kjbmUZIO8yZ9HE0XvMnsQybQv0FfQKlERPSZ51eHnlAfV1SoPv10Yy+xUGUJ | ||
90 | +5lhCLkMaTLTwJUdZ+gQek9QmRkpQgbLevni3/GcV4clXhB4PY9bpYrrWX1Uu6lzG | ||
91 | +KAgEJTm4Diup8kyXHAc/DVL17e8vgg8CAwEAAaOB8jCB7zAfBgNVHSMEGDAWgBSg | ||
92 | +EQojPpbxB+zirynvgqV/0DCktDAdBgNVHQ4EFgQUU3m/WqorSs9UgOHYm8Cd8rID | ||
93 | +ZsswDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMBAf8wEQYDVR0gBAowCDAG | ||
94 | +BgRVHSAAMEMGA1UdHwQ8MDowOKA2oDSGMmh0dHA6Ly9jcmwuY29tb2RvY2EuY29t | ||
95 | +L0FBQUNlcnRpZmljYXRlU2VydmljZXMuY3JsMDQGCCsGAQUFBwEBBCgwJjAkBggr | ||
96 | +BgEFBQcwAYYYaHR0cDovL29jc3AuY29tb2RvY2EuY29tMA0GCSqGSIb3DQEBDAUA | ||
97 | +A4IBAQAYh1HcdCE9nIrgJ7cz0C7M7PDmy14R3iJvm3WOnnL+5Nb+qh+cli3vA0p+ | ||
98 | +rvSNb3I8QzvAP+u431yqqcau8vzY7qN7Q/aGNnwU4M309z/+3ri0ivCRlv79Q2R+ | ||
99 | +/czSAaF9ffgZGclCKxO/WIu6pKJmBHaIkU4MiRTOok3JMrO66BQavHHxW/BBC5gA | ||
100 | +CiIDEOUMsfnNkjcZ7Tvx5Dq2+UUTJnWvu6rvP3t3O9LEApE9GQDTF1w52z97GA1F | ||
101 | +zZOFli9d31kWTz9RvdVFGD/tSo7oBmF0Ixa1DVBzJ0RHfxBdiSprhTEUxOipakyA | ||
102 | +vGp4z7h/jnZymQyd/teRCBaho1+V | ||
103 | +-----END CERTIFICATE----- |
1 | +apiVersion: v1 | ||
2 | +kind: Service | ||
3 | +metadata: | ||
4 | + name: character-library-metadata-bastion | ||
5 | + namespace: <replace-your-k8s-namespace> | ||
6 | + labels: | ||
7 | + k8s-app: character-library-metadata-bastion | ||
8 | +spec: | ||
9 | + ports: | ||
10 | + - name: "http" | ||
11 | + port: 80 | ||
12 | + targetPort: 8082 | ||
13 | + selector: | ||
14 | + k8s-app: character-library-metadata-bastion | ||
15 | +--- | ||
16 | +apiVersion: extensions/v1beta1 | ||
17 | +kind: Deployment | ||
18 | +metadata: | ||
19 | + name: character-library-metadata-bastion | ||
20 | + namespace: <replace-your-k8s-namespace> | ||
21 | + labels: | ||
22 | + k8s-app: character-library-metadata-bastion | ||
23 | +spec: | ||
24 | + replicas: 1 | ||
25 | + template: | ||
26 | + metadata: | ||
27 | + labels: | ||
28 | + k8s-app: character-library-metadata-bastion | ||
29 | + spec: | ||
30 | + affinity: | ||
31 | + nodeAffinity: | ||
32 | + preferredDuringSchedulingIgnoredDuringExecution: | ||
33 | + - preference: {} | ||
34 | + weight: 100 | ||
35 | + requiredDuringSchedulingIgnoredDuringExecution: | ||
36 | + nodeSelectorTerms: | ||
37 | + - matchExpressions: | ||
38 | + - key: kubernetes.io/hostname | ||
39 | + operator: In | ||
40 | + values: | ||
41 | + - cn-hangzhou.i-bp1djh1xn7taumbue1ze | ||
42 | + - cn-hangzhou.i-bp1djh1xn7taumbue1zd | ||
43 | + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb | ||
44 | + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy | ||
45 | + containers: | ||
46 | + - name: character-library-metadata-bastion | ||
47 | + image: 192.168.0.243:5000/mmm/character-library-metadata-bastion:dev | ||
48 | + imagePullPolicy: Always | ||
49 | + ports: | ||
50 | + - containerPort: 8082 | ||
51 | + volumeMounts: | ||
52 | + - mountPath: /opt/logs | ||
53 | + name: accesslogs | ||
54 | + env: | ||
55 | + - name: LOG_LEVEL | ||
56 | + value: "debug" | ||
57 | + - name: ERROR_BASE_CODE | ||
58 | + value: "1" | ||
59 | + - name: ERROR_BASE_CODE_MULTIPLE | ||
60 | + value: "1000" | ||
61 | + volumes: | ||
62 | + - name: accesslogs | ||
63 | + emptyDir: {} |
deploy/k8s/dev/install.sh
0 → 100644
1 | +#!/bin/bash | ||
2 | +export PATH=/root/local/bin:$PATH | ||
3 | +kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | ||
4 | +if [ "$?" == "1" ];then | ||
5 | + kubectl create -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml --record | ||
6 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q character-library-metadata-bastion | ||
7 | + if [ "$?" == "0" ];then | ||
8 | + echo "character-library-metadata-bastion service install success!" | ||
9 | + else | ||
10 | + echo "character-library-metadata-bastion service install fail!" | ||
11 | + fi | ||
12 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | ||
13 | + if [ "$?" == "0" ];then | ||
14 | + echo "character-library-metadata-bastion deployment install success!" | ||
15 | + else | ||
16 | + echo "character-library-metadata-bastion deployment install fail!" | ||
17 | + fi | ||
18 | +else | ||
19 | + kubectl delete -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml | ||
20 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q character-library-metadata-bastion | ||
21 | + while [ "$?" == "0" ] | ||
22 | + do | ||
23 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q character-library-metadata-bastion | ||
24 | + done | ||
25 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | ||
26 | + while [ "$?" == "0" ] | ||
27 | + do | ||
28 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | ||
29 | + done | ||
30 | + kubectl create -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml --record | ||
31 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q character-library-metadata-bastion | ||
32 | + if [ "$?" == "0" ];then | ||
33 | + echo "character-library-metadata-bastion service update success!" | ||
34 | + else | ||
35 | + echo "character-library-metadata-bastion service update fail!" | ||
36 | + fi | ||
37 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | ||
38 | + if [ "$?" == "0" ];then | ||
39 | + echo "character-library-metadata-bastion deployment update success!" | ||
40 | + else | ||
41 | + echo "character-library-metadata-bastion deployment update fail!" | ||
42 | + fi | ||
43 | +fi |
1 | +version: v1 | ||
2 | +kind: HttpApi | ||
3 | +metadata: | ||
4 | + service: file | ||
5 | + path: /files | ||
6 | + endpoints: | ||
7 | + - method: createFile | ||
8 | + route: | ||
9 | + post: / | ||
10 | + - method: updateFile | ||
11 | + route: | ||
12 | + put: /{fileId} | ||
13 | + - method: getFile | ||
14 | + route: | ||
15 | + get: /{fileId} | ||
16 | + - method: removeFile | ||
17 | + route: | ||
18 | + delete: /{fileId} | ||
19 | + - method: listFile | ||
20 | + route: | ||
21 | + get: / | ||
22 | + params: | ||
23 | + - name: offset | ||
24 | + - name: limit | ||
25 | + - method: loadDataTable | ||
26 | + route: | ||
27 | + post: /files/load-data-table | ||
28 | + - method: editDataTable | ||
29 | + route: | ||
30 | + post: /files/edit-data-table | ||
31 | + - method: flushDataTable | ||
32 | + route: | ||
33 | + post: /files/flush-data-table | ||
34 | + - method: generateMainTable | ||
35 | + route: | ||
36 | + post: /files/generate-main-table |
1 | +version: v1 | ||
2 | +kind: Schema | ||
3 | +metadata: | ||
4 | + name: field | ||
5 | + description: 字段 | ||
6 | + attributes: | ||
7 | + - ref: fieldId | ||
8 | + required: true | ||
9 | + - ref: index | ||
10 | + required: true | ||
11 | + - ref: name | ||
12 | + required: true | ||
13 | + - ref: SQLName | ||
14 | + required: true | ||
15 | + - ref: SQLType | ||
16 | + required: true | ||
17 | + - ref: description | ||
18 | + required: true | ||
19 | + - ref: flag | ||
20 | + required: true |
1 | +version: v1 | ||
2 | +kind: Schema | ||
3 | +metadata: | ||
4 | + name: file | ||
5 | + description: 文件 | ||
6 | + attributes: | ||
7 | + - ref: fileId | ||
8 | + required: true | ||
9 | + - ref: fileType | ||
10 | + required: true | ||
11 | + - ref: fileInfo | ||
12 | + required: true | ||
13 | + - ref: sourceFileId | ||
14 | + required: true | ||
15 | + - ref: operator | ||
16 | + required: true | ||
17 | + - ref: createdAt | ||
18 | + required: true | ||
19 | + - ref: updatedAt | ||
20 | + required: true | ||
21 | + - ref: deletedAt | ||
22 | + required: true | ||
23 | + - ref: version | ||
24 | + required: true |
1 | +version: v1 | ||
2 | +kind: Schema | ||
3 | +metadata: | ||
4 | + name: logEntry | ||
5 | + description: 日志内容 | ||
6 | + attributes: | ||
7 | + - ref: objectName | ||
8 | + required: true | ||
9 | + - ref: objectType | ||
10 | + required: true | ||
11 | + - ref: operationType | ||
12 | + required: true | ||
13 | + - ref: content | ||
14 | + required: true | ||
15 | + - ref: operatorName | ||
16 | + required: true |
1 | +version: v1 | ||
2 | +kind: Schema | ||
3 | +metadata: | ||
4 | + name: table | ||
5 | + description: 表 | ||
6 | + attributes: | ||
7 | + - ref: tableId | ||
8 | + required: true | ||
9 | + - ref: tableType | ||
10 | + required: true | ||
11 | + - ref: name | ||
12 | + required: true | ||
13 | + - ref: SQLName | ||
14 | + required: true | ||
15 | + - ref: parentId | ||
16 | + required: true | ||
17 | + - ref: dataFieldIndex | ||
18 | + required: true | ||
19 | + - ref: PK | ||
20 | + required: true | ||
21 | + - ref: dataFields | ||
22 | + required: true | ||
23 | + - ref: manualFields | ||
24 | + required: true | ||
25 | + - ref: createdAt | ||
26 | + required: true | ||
27 | + - ref: updatedAt | ||
28 | + required: true | ||
29 | + - ref: deletedAt | ||
30 | + required: true | ||
31 | + - ref: version | ||
32 | + required: true |
1 | +version: v1 | ||
2 | +kind: Method | ||
3 | +metadata: | ||
4 | + name: createFile | ||
5 | + type: command | ||
6 | + description: 创建文件服务 | ||
7 | + payload: | ||
8 | + - ref: name | ||
9 | + required: true | ||
10 | + - ref: url | ||
11 | + required: true | ||
12 | + - ref: fileSize | ||
13 | + required: true | ||
14 | + result: | ||
15 | + - name: file | ||
16 | + type: | ||
17 | + schema: file | ||
18 | + required: true |
1 | +version: v1 | ||
2 | +kind: Method | ||
3 | +metadata: | ||
4 | + name: listFile | ||
5 | + type: query | ||
6 | + description: 返回文件服务列表 | ||
7 | + payload: | ||
8 | + - ref: offset | ||
9 | + required: true | ||
10 | + - ref: limit | ||
11 | + required: true | ||
12 | + result: | ||
13 | + - ref: count | ||
14 | + required: true | ||
15 | + - name: files | ||
16 | + type: | ||
17 | + array: file | ||
18 | + required: true |
document/openapi/swagger.yaml
0 → 100644
1 | +swagger: "2.0" | ||
2 | +info: | ||
3 | + title: "" | ||
4 | + description: 字库元数据堡垒 | ||
5 | + contact: | ||
6 | + name: ttt | ||
7 | + email: "" | ||
8 | + home: "" | ||
9 | + version: 0.0.1 | ||
10 | +consumes: | ||
11 | +- application/json | ||
12 | +- application/xml | ||
13 | +produces: | ||
14 | +- application/json | ||
15 | +- application/xml | ||
16 | +paths: | ||
17 | + /files: | ||
18 | + get: | ||
19 | + tags: | ||
20 | + - file | ||
21 | + summary: 返回文件服务列表 | ||
22 | + description: 返回文件服务列表 | ||
23 | + operationId: file#listFile | ||
24 | + parameters: | ||
25 | + - name: offset | ||
26 | + in: query | ||
27 | + description: 查询偏离量 | ||
28 | + required: false | ||
29 | + type: integer | ||
30 | + - name: limit | ||
31 | + in: query | ||
32 | + description: 查询限制 | ||
33 | + required: false | ||
34 | + type: integer | ||
35 | + responses: | ||
36 | + "200": | ||
37 | + description: OK response. | ||
38 | + schema: | ||
39 | + $ref: '#/definitions/FileListFileResponseBody' | ||
40 | + schemes: | ||
41 | + - http | ||
42 | + post: | ||
43 | + tags: | ||
44 | + - file | ||
45 | + summary: 创建文件服务 | ||
46 | + description: 创建文件服务 | ||
47 | + operationId: file#createFile | ||
48 | + parameters: | ||
49 | + - name: CreateFileRequestBody | ||
50 | + in: body | ||
51 | + required: true | ||
52 | + schema: | ||
53 | + $ref: '#/definitions/FileCreateFileRequestBody' | ||
54 | + responses: | ||
55 | + "200": | ||
56 | + description: OK response. | ||
57 | + schema: | ||
58 | + $ref: '#/definitions/FileCreateFileResponseBody' | ||
59 | + schemes: | ||
60 | + - http | ||
61 | + /files/{fileId}: | ||
62 | + get: | ||
63 | + tags: | ||
64 | + - file | ||
65 | + summary: 返回文件服务 | ||
66 | + description: 返回文件服务 | ||
67 | + operationId: file#getFile | ||
68 | + parameters: | ||
69 | + - name: fileId | ||
70 | + in: path | ||
71 | + description: 文件ID | ||
72 | + required: true | ||
73 | + type: integer | ||
74 | + responses: | ||
75 | + "200": | ||
76 | + description: OK response. | ||
77 | + schema: | ||
78 | + $ref: '#/definitions/FileGetFileResponseBody' | ||
79 | + schemes: | ||
80 | + - http | ||
81 | + put: | ||
82 | + tags: | ||
83 | + - file | ||
84 | + summary: 更新文件服务 | ||
85 | + description: 更新文件服务 | ||
86 | + operationId: file#updateFile | ||
87 | + parameters: | ||
88 | + - name: fileId | ||
89 | + in: path | ||
90 | + description: 文件ID | ||
91 | + required: true | ||
92 | + type: integer | ||
93 | + responses: | ||
94 | + "200": | ||
95 | + description: OK response. | ||
96 | + schema: | ||
97 | + $ref: '#/definitions/FileUpdateFileResponseBody' | ||
98 | + schemes: | ||
99 | + - http | ||
100 | + delete: | ||
101 | + tags: | ||
102 | + - file | ||
103 | + summary: 移除文件服务 | ||
104 | + description: 移除文件服务 | ||
105 | + operationId: file#removeFile | ||
106 | + parameters: | ||
107 | + - name: fileId | ||
108 | + in: path | ||
109 | + description: 文件ID | ||
110 | + required: true | ||
111 | + type: integer | ||
112 | + responses: | ||
113 | + "200": | ||
114 | + description: OK response. | ||
115 | + schema: | ||
116 | + $ref: '#/definitions/FileRemoveFileResponseBody' | ||
117 | + schemes: | ||
118 | + - http | ||
119 | + /files/files/edit-data-table: | ||
120 | + post: | ||
121 | + tags: | ||
122 | + - file | ||
123 | + summary: 编辑表格数据 | ||
124 | + description: 编辑表格数据 | ||
125 | + operationId: file#editDataTable | ||
126 | + parameters: | ||
127 | + - name: EditDataTableRequestBody | ||
128 | + in: body | ||
129 | + required: true | ||
130 | + schema: | ||
131 | + $ref: '#/definitions/FileEditDataTableRequestBody' | ||
132 | + responses: | ||
133 | + "200": | ||
134 | + description: OK response. | ||
135 | + schema: | ||
136 | + $ref: '#/definitions/FileEditDataTableResponseBody' | ||
137 | + schemes: | ||
138 | + - http | ||
139 | + /files/files/flush-data-table: | ||
140 | + post: | ||
141 | + tags: | ||
142 | + - file | ||
143 | + summary: 持久化表格数据 | ||
144 | + description: 持久化表格数据 | ||
145 | + operationId: file#flushDataTable | ||
146 | + parameters: | ||
147 | + - name: FlushDataTableRequestBody | ||
148 | + in: body | ||
149 | + required: true | ||
150 | + schema: | ||
151 | + $ref: '#/definitions/FileFlushDataTableRequestBody' | ||
152 | + responses: | ||
153 | + "200": | ||
154 | + description: OK response. | ||
155 | + schema: | ||
156 | + $ref: '#/definitions/FileFlushDataTableResponseBody' | ||
157 | + schemes: | ||
158 | + - http | ||
159 | + /files/files/generate-main-table: | ||
160 | + post: | ||
161 | + tags: | ||
162 | + - file | ||
163 | + summary: 生成主表 | ||
164 | + description: 生成主表 | ||
165 | + operationId: file#generateMainTable | ||
166 | + parameters: | ||
167 | + - name: GenerateMainTableRequestBody | ||
168 | + in: body | ||
169 | + required: true | ||
170 | + schema: | ||
171 | + $ref: '#/definitions/FileGenerateMainTableRequestBody' | ||
172 | + responses: | ||
173 | + "200": | ||
174 | + description: OK response. | ||
175 | + schema: | ||
176 | + $ref: '#/definitions/FileGenerateMainTableResponseBody' | ||
177 | + schemes: | ||
178 | + - http | ||
179 | + /files/files/load-data-table: | ||
180 | + post: | ||
181 | + tags: | ||
182 | + - file | ||
183 | + summary: 加载表格数据 | ||
184 | + description: 加载表格数据 | ||
185 | + operationId: file#loadDataTable | ||
186 | + parameters: | ||
187 | + - name: LoadDataTableRequestBody | ||
188 | + in: body | ||
189 | + required: true | ||
190 | + schema: | ||
191 | + $ref: '#/definitions/FileLoadDataTableRequestBody' | ||
192 | + responses: | ||
193 | + "200": | ||
194 | + description: OK response. | ||
195 | + schema: | ||
196 | + $ref: '#/definitions/FileLoadDataTableResponseBody' | ||
197 | + schemes: | ||
198 | + - http | ||
199 | +definitions: | ||
200 | + FileCreateFileRequestBody: | ||
201 | + title: FileCreateFileRequestBody | ||
202 | + type: object | ||
203 | + properties: | ||
204 | + fileSize: | ||
205 | + type: integer | ||
206 | + description: 文件大小 | ||
207 | + required: | ||
208 | + - fileSize | ||
209 | + name: | ||
210 | + type: string | ||
211 | + description: 名称 | ||
212 | + required: | ||
213 | + - name | ||
214 | + url: | ||
215 | + type: string | ||
216 | + description: 文件地址 | ||
217 | + required: | ||
218 | + - url | ||
219 | + FileCreateFileResponseBody: | ||
220 | + title: 'Mediatype identifier: FileCreateFileResponseBody' | ||
221 | + type: object | ||
222 | + properties: | ||
223 | + file: | ||
224 | + $ref: '#/definitions/fileResponseBody' | ||
225 | + FileEditDataTableRequestBody: | ||
226 | + title: FileEditDataTableRequestBody | ||
227 | + type: object | ||
228 | + properties: | ||
229 | + fileId: | ||
230 | + type: integer | ||
231 | + description: 文件ID | ||
232 | + required: | ||
233 | + - fileId | ||
234 | + FileEditDataTableResponseBody: | ||
235 | + title: 'Mediatype identifier: FileEditDataTableResponseBody' | ||
236 | + type: object | ||
237 | + properties: | ||
238 | + file: | ||
239 | + $ref: '#/definitions/fileResponseBody' | ||
240 | + FileFlushDataTableRequestBody: | ||
241 | + title: FileFlushDataTableRequestBody | ||
242 | + type: object | ||
243 | + properties: | ||
244 | + fileId: | ||
245 | + type: integer | ||
246 | + description: 文件ID | ||
247 | + required: | ||
248 | + - fileId | ||
249 | + FileFlushDataTableResponseBody: | ||
250 | + title: 'Mediatype identifier: FileFlushDataTableResponseBody' | ||
251 | + type: object | ||
252 | + properties: | ||
253 | + file: | ||
254 | + $ref: '#/definitions/fileResponseBody' | ||
255 | + FileGenerateMainTableRequestBody: | ||
256 | + title: FileGenerateMainTableRequestBody | ||
257 | + type: object | ||
258 | + properties: | ||
259 | + fileId: | ||
260 | + type: integer | ||
261 | + description: 文件ID | ||
262 | + required: | ||
263 | + - fileId | ||
264 | + FileGenerateMainTableResponseBody: | ||
265 | + title: 'Mediatype identifier: FileGenerateMainTableResponseBody' | ||
266 | + type: object | ||
267 | + properties: | ||
268 | + file: | ||
269 | + $ref: '#/definitions/fileResponseBody' | ||
270 | + FileGetFileResponseBody: | ||
271 | + title: 'Mediatype identifier: FileGetFileResponseBody' | ||
272 | + type: object | ||
273 | + properties: | ||
274 | + file: | ||
275 | + $ref: '#/definitions/fileResponseBody' | ||
276 | + FileListFileResponseBody: | ||
277 | + title: 'Mediatype identifier: FileListFileResponseBody' | ||
278 | + type: object | ||
279 | + properties: | ||
280 | + count: | ||
281 | + type: integer | ||
282 | + description: 匹配数目 | ||
283 | + required: | ||
284 | + - count | ||
285 | + files: | ||
286 | + type: array | ||
287 | + items: | ||
288 | + $ref: '#/definitions/fileResponseBody' | ||
289 | + required: | ||
290 | + - files | ||
291 | + FileLoadDataTableRequestBody: | ||
292 | + title: FileLoadDataTableRequestBody | ||
293 | + type: object | ||
294 | + properties: | ||
295 | + fileId: | ||
296 | + type: integer | ||
297 | + description: 文件ID | ||
298 | + required: | ||
299 | + - fileId | ||
300 | + FileLoadDataTableResponseBody: | ||
301 | + title: 'Mediatype identifier: FileLoadDataTableResponseBody' | ||
302 | + type: object | ||
303 | + properties: | ||
304 | + file: | ||
305 | + $ref: '#/definitions/fileResponseBody' | ||
306 | + FileRemoveFileResponseBody: | ||
307 | + title: 'Mediatype identifier: FileRemoveFileResponseBody' | ||
308 | + type: object | ||
309 | + properties: | ||
310 | + file: | ||
311 | + $ref: '#/definitions/fileResponseBody' | ||
312 | + FileUpdateFileResponseBody: | ||
313 | + title: 'Mediatype identifier: FileUpdateFileResponseBody' | ||
314 | + type: object | ||
315 | + properties: | ||
316 | + file: | ||
317 | + $ref: '#/definitions/fileResponseBody' | ||
318 | + fileResponseBody: | ||
319 | + title: fileResponseBody | ||
320 | + type: object | ||
321 | + properties: | ||
322 | + createdAt: | ||
323 | + type: string | ||
324 | + description: 创建时间 | ||
325 | + required: | ||
326 | + - createdAt | ||
327 | + deletedAt: | ||
328 | + type: string | ||
329 | + description: 删除时间 | ||
330 | + required: | ||
331 | + - deletedAt | ||
332 | + fileId: | ||
333 | + type: integer | ||
334 | + description: 文件ID | ||
335 | + required: | ||
336 | + - fileId | ||
337 | + fileInfo: | ||
338 | + type: string | ||
339 | + description: 文件信息 | ||
340 | + required: | ||
341 | + - fileInfo | ||
342 | + fileType: | ||
343 | + type: string | ||
344 | + description: 文件类型 | ||
345 | + required: | ||
346 | + - fileType | ||
347 | + operator: | ||
348 | + type: string | ||
349 | + description: 操作人 | ||
350 | + required: | ||
351 | + - operator | ||
352 | + sourceFileId: | ||
353 | + type: string | ||
354 | + description: 源文件Id(FileType为TemporaryFile或VerifiedFile时有值) | ||
355 | + required: | ||
356 | + - sourceFileId | ||
357 | + updatedAt: | ||
358 | + type: string | ||
359 | + description: 更新时间 | ||
360 | + required: | ||
361 | + - updatedAt | ||
362 | + version: | ||
363 | + type: integer | ||
364 | + description: 版本 | ||
365 | + required: | ||
366 | + - version | ||
367 | + description: 文件 |
go.mod
0 → 100644
1 | +module gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion | ||
2 | + | ||
3 | +go 1.16 | ||
4 | + | ||
5 | +require ( | ||
6 | + github.com/Shopify/sarama v1.25.0 | ||
7 | + github.com/ajg/form v1.5.1 // indirect | ||
8 | + github.com/beego/beego/v2 v2.0.1 | ||
9 | + github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | ||
10 | + github.com/fatih/structs v1.1.0 // indirect | ||
11 | + github.com/gavv/httpexpect v2.0.0+incompatible | ||
12 | + github.com/go-pg/pg/v10 v10.9.0 | ||
13 | + github.com/go-redis/redis v6.15.9+incompatible // indirect | ||
14 | + github.com/go-redis/redis/v7 v7.4.1 // indirect | ||
15 | + github.com/golang/snappy v0.0.3 // indirect | ||
16 | + github.com/google/go-cmp v0.5.6 // indirect | ||
17 | + github.com/google/go-querystring v1.1.0 // indirect | ||
18 | + github.com/google/uuid v1.3.0 // indirect | ||
19 | + github.com/imkira/go-interpol v1.1.0 // indirect | ||
20 | + github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 | ||
21 | + github.com/moul/http2curl v1.0.0 // indirect | ||
22 | + github.com/onsi/ginkgo v1.15.2 | ||
23 | + github.com/onsi/gomega v1.11.0 | ||
24 | + github.com/sergi/go-diff v1.2.0 // indirect | ||
25 | + github.com/smartystreets/goconvey v1.7.2 // indirect | ||
26 | + github.com/valyala/fasthttp v1.38.0 // indirect | ||
27 | + github.com/xeipuuv/gojsonschema v1.2.0 // indirect | ||
28 | + github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect | ||
29 | + github.com/yudai/gojsondiff v1.0.0 // indirect | ||
30 | + github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect | ||
31 | + github.com/yudai/pp v2.0.1+incompatible // indirect | ||
32 | +) | ||
33 | + | ||
34 | +replace github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 |
main.go
0 → 100644
1 | +package main | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/beego/beego/v2/server/web" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
9 | + "time" | ||
10 | + | ||
11 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
12 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
13 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" | ||
14 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
15 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego" | ||
16 | +) | ||
17 | + | ||
18 | +func main() { | ||
19 | + defer func() { | ||
20 | + if r := recover(); r != nil { | ||
21 | + log.Logger.Error(fmt.Sprintf("%v", r)) | ||
22 | + } | ||
23 | + }() | ||
24 | + | ||
25 | + log.InitLogHook(constant.ENABLE_KAFKA_LOG, true) | ||
26 | + redis.InitRedis() | ||
27 | + | ||
28 | + time.Sleep(time.Second) | ||
29 | + log.Logger.Info("server start!") | ||
30 | + web.Run() | ||
31 | + log.Logger.Info("server stop!") | ||
32 | +} |
pkg/application/factory/domain_service.go
0 → 100644
1 | +package factory |
pkg/application/factory/repository.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" | ||
7 | +) | ||
8 | + | ||
9 | +func CreateTableRepository(options map[string]interface{}) (domain.TableRepository, error) { | ||
10 | + var transactionContext *pg.TransactionContext | ||
11 | + if value, ok := options["transactionContext"]; ok { | ||
12 | + transactionContext = value.(*pg.TransactionContext) | ||
13 | + } | ||
14 | + return repository.NewTableRepository(transactionContext) | ||
15 | +} | ||
16 | + | ||
17 | +func CreateLogRepository(options map[string]interface{}) (domain.LogRepository, error) { | ||
18 | + var transactionContext *pg.TransactionContext | ||
19 | + if value, ok := options["transactionContext"]; ok { | ||
20 | + transactionContext = value.(*pg.TransactionContext) | ||
21 | + } | ||
22 | + return repository.NewLogRepository(transactionContext) | ||
23 | +} | ||
24 | + | ||
25 | +func CreateFileRepository(options map[string]interface{}) (domain.FileRepository, error) { | ||
26 | + var transactionContext *pg.TransactionContext | ||
27 | + if value, ok := options["transactionContext"]; ok { | ||
28 | + transactionContext = value.(*pg.TransactionContext) | ||
29 | + } | ||
30 | + return repository.NewFileRepository(transactionContext) | ||
31 | +} |
pkg/application/factory/transaction.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + pG "github.com/linmadan/egglib-go/transaction/pg" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
7 | +) | ||
8 | + | ||
9 | +func CreateTransactionContext(options map[string]interface{}) (application.TransactionContext, error) { | ||
10 | + return pG.NewPGTransactionContext(pg.DB), nil | ||
11 | +} |
pkg/application/file/command/create_file.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type CreateFileCommand struct { | ||
12 | + // 名称 | ||
13 | + Name string `cname:"名称" json:"name" valid:"Required"` | ||
14 | + // 文件地址 | ||
15 | + Url string `cname:"文件地址" json:"url" valid:"Required"` | ||
16 | + // 文件大小 | ||
17 | + FileSize int `cname:"文件大小" json:"fileSize" valid:"Required"` | ||
18 | +} | ||
19 | + | ||
20 | +func (createFileCommand *CreateFileCommand) Valid(validation *validation.Validation) { | ||
21 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
22 | +} | ||
23 | + | ||
24 | +func (createFileCommand *CreateFileCommand) ValidateCommand() error { | ||
25 | + valid := validation.Validation{} | ||
26 | + b, err := valid.Valid(createFileCommand) | ||
27 | + if err != nil { | ||
28 | + return err | ||
29 | + } | ||
30 | + if !b { | ||
31 | + elem := reflect.TypeOf(createFileCommand).Elem() | ||
32 | + for _, validErr := range valid.Errors { | ||
33 | + field, isExist := elem.FieldByName(validErr.Field) | ||
34 | + if isExist { | ||
35 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
36 | + } else { | ||
37 | + return fmt.Errorf(validErr.Message) | ||
38 | + } | ||
39 | + } | ||
40 | + } | ||
41 | + return nil | ||
42 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type EditDataTableCommand struct { | ||
12 | + // 文件ID | ||
13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (editDataTableCommand *EditDataTableCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (editDataTableCommand *EditDataTableCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(editDataTableCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(editDataTableCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type FlushDataTableCommand struct { | ||
12 | + // 文件ID | ||
13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (flushDataTableCommand *FlushDataTableCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (flushDataTableCommand *FlushDataTableCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(flushDataTableCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(flushDataTableCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GenerateMainTableCommand struct { | ||
12 | + // 文件ID | ||
13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (generateMainTableCommand *GenerateMainTableCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (generateMainTableCommand *GenerateMainTableCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(generateMainTableCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(generateMainTableCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type LoadDataTableCommand struct { | ||
12 | + // 文件ID | ||
13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (loadDataTableCommand *LoadDataTableCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (loadDataTableCommand *LoadDataTableCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(loadDataTableCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(loadDataTableCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
pkg/application/file/command/remove_file.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type RemoveFileCommand struct { | ||
12 | + // 文件ID | ||
13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (removeFileCommand *RemoveFileCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (removeFileCommand *RemoveFileCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(removeFileCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(removeFileCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
pkg/application/file/command/update_file.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type UpdateFileCommand struct { | ||
12 | + // 文件ID | ||
13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (updateFileCommand *UpdateFileCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (updateFileCommand *UpdateFileCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(updateFileCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(updateFileCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
pkg/application/file/query/get_file.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetFileQuery struct { | ||
12 | + // 文件ID | ||
13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (getFileQuery *GetFileQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (getFileQuery *GetFileQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(getFileQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(getFileQuery).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
pkg/application/file/query/list_file.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type ListFileQuery struct { | ||
12 | + // 查询偏离量 | ||
13 | + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | ||
14 | + // 查询限制 | ||
15 | + Limit int `cname:"查询限制" json:"limit" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (listFileQuery *ListFileQuery) Valid(validation *validation.Validation) { | ||
19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (listFileQuery *ListFileQuery) ValidateQuery() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(listFileQuery) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + elem := reflect.TypeOf(listFileQuery).Elem() | ||
30 | + for _, validErr := range valid.Errors { | ||
31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
32 | + if isExist { | ||
33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
34 | + } else { | ||
35 | + return fmt.Errorf(validErr.Message) | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | + return nil | ||
40 | +} |
pkg/application/file/service/file.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
11 | +) | ||
12 | + | ||
13 | +// 文件服务 | ||
14 | +type FileService struct { | ||
15 | +} | ||
16 | + | ||
17 | +// 创建文件服务 | ||
18 | +func (fileService *FileService) CreateFile(createFileCommand *command.CreateFileCommand) (interface{}, error) { | ||
19 | + if err := createFileCommand.ValidateCommand(); err != nil { | ||
20 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
21 | + } | ||
22 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
23 | + if err != nil { | ||
24 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
25 | + } | ||
26 | + if err := transactionContext.StartTransaction(); err != nil { | ||
27 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
28 | + } | ||
29 | + defer func() { | ||
30 | + transactionContext.RollbackTransaction() | ||
31 | + }() | ||
32 | + newFile := &domain.File{ | ||
33 | + //Name: createFileCommand.Name, | ||
34 | + //Url: createFileCommand.Url, | ||
35 | + //FileSize: createFileCommand.FileSize, | ||
36 | + } | ||
37 | + var fileRepository domain.FileRepository | ||
38 | + if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
39 | + "transactionContext": transactionContext, | ||
40 | + }); err != nil { | ||
41 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
42 | + } else { | ||
43 | + fileRepository = value | ||
44 | + } | ||
45 | + if file, err := fileRepository.Save(newFile); err != nil { | ||
46 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
47 | + } else { | ||
48 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
49 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
50 | + } | ||
51 | + return file, nil | ||
52 | + } | ||
53 | +} | ||
54 | + | ||
55 | +// 编辑表格数据 | ||
56 | +func (fileService *FileService) EditDataTable(editDataTableCommand *command.EditDataTableCommand) (interface{}, error) { | ||
57 | + if err := editDataTableCommand.ValidateCommand(); err != nil { | ||
58 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
59 | + } | ||
60 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
61 | + if err != nil { | ||
62 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
63 | + } | ||
64 | + if err := transactionContext.StartTransaction(); err != nil { | ||
65 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
66 | + } | ||
67 | + defer func() { | ||
68 | + transactionContext.RollbackTransaction() | ||
69 | + }() | ||
70 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
71 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
72 | + } | ||
73 | + return nil, nil | ||
74 | +} | ||
75 | + | ||
76 | +// 持久化表格数据 | ||
77 | +func (fileService *FileService) FlushDataTable(flushDataTableCommand *command.FlushDataTableCommand) (interface{}, error) { | ||
78 | + if err := flushDataTableCommand.ValidateCommand(); err != nil { | ||
79 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
80 | + } | ||
81 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
82 | + if err != nil { | ||
83 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
84 | + } | ||
85 | + if err := transactionContext.StartTransaction(); err != nil { | ||
86 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
87 | + } | ||
88 | + defer func() { | ||
89 | + transactionContext.RollbackTransaction() | ||
90 | + }() | ||
91 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
92 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
93 | + } | ||
94 | + return nil, nil | ||
95 | +} | ||
96 | + | ||
97 | +// 生成主表 | ||
98 | +func (fileService *FileService) GenerateMainTable(generateMainTableCommand *command.GenerateMainTableCommand) (interface{}, error) { | ||
99 | + if err := generateMainTableCommand.ValidateCommand(); err != nil { | ||
100 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
101 | + } | ||
102 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
103 | + if err != nil { | ||
104 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
105 | + } | ||
106 | + if err := transactionContext.StartTransaction(); err != nil { | ||
107 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
108 | + } | ||
109 | + defer func() { | ||
110 | + transactionContext.RollbackTransaction() | ||
111 | + }() | ||
112 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
113 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
114 | + } | ||
115 | + return nil, nil | ||
116 | +} | ||
117 | + | ||
118 | +// 返回文件服务 | ||
119 | +func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (interface{}, error) { | ||
120 | + if err := getFileQuery.ValidateQuery(); err != nil { | ||
121 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
122 | + } | ||
123 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
124 | + if err != nil { | ||
125 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
126 | + } | ||
127 | + if err := transactionContext.StartTransaction(); err != nil { | ||
128 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
129 | + } | ||
130 | + defer func() { | ||
131 | + transactionContext.RollbackTransaction() | ||
132 | + }() | ||
133 | + var fileRepository domain.FileRepository | ||
134 | + if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
135 | + "transactionContext": transactionContext, | ||
136 | + }); err != nil { | ||
137 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
138 | + } else { | ||
139 | + fileRepository = value | ||
140 | + } | ||
141 | + file, err := fileRepository.FindOne(map[string]interface{}{"fileId": getFileQuery.FileId}) | ||
142 | + if err != nil { | ||
143 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
144 | + } | ||
145 | + if file == nil { | ||
146 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getFileQuery.FileId))) | ||
147 | + } else { | ||
148 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
149 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
150 | + } | ||
151 | + return file, nil | ||
152 | + } | ||
153 | +} | ||
154 | + | ||
155 | +// 返回文件服务列表 | ||
156 | +func (fileService *FileService) ListFile(listFileQuery *query.ListFileQuery) (interface{}, error) { | ||
157 | + if err := listFileQuery.ValidateQuery(); err != nil { | ||
158 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
159 | + } | ||
160 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
161 | + if err != nil { | ||
162 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
163 | + } | ||
164 | + if err := transactionContext.StartTransaction(); err != nil { | ||
165 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
166 | + } | ||
167 | + defer func() { | ||
168 | + transactionContext.RollbackTransaction() | ||
169 | + }() | ||
170 | + var fileRepository domain.FileRepository | ||
171 | + if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
172 | + "transactionContext": transactionContext, | ||
173 | + }); err != nil { | ||
174 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
175 | + } else { | ||
176 | + fileRepository = value | ||
177 | + } | ||
178 | + if count, files, err := fileRepository.Find(tool_funs.SimpleStructToMap(listFileQuery)); err != nil { | ||
179 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
180 | + } else { | ||
181 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
182 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
183 | + } | ||
184 | + return map[string]interface{}{ | ||
185 | + "count": count, | ||
186 | + "files": files, | ||
187 | + }, nil | ||
188 | + } | ||
189 | +} | ||
190 | + | ||
191 | +// 加载表格数据 | ||
192 | +func (fileService *FileService) LoadDataTable(loadDataTableCommand *command.LoadDataTableCommand) (interface{}, error) { | ||
193 | + if err := loadDataTableCommand.ValidateCommand(); err != nil { | ||
194 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
195 | + } | ||
196 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
197 | + if err != nil { | ||
198 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
199 | + } | ||
200 | + if err := transactionContext.StartTransaction(); err != nil { | ||
201 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
202 | + } | ||
203 | + defer func() { | ||
204 | + transactionContext.RollbackTransaction() | ||
205 | + }() | ||
206 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
207 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
208 | + } | ||
209 | + return nil, nil | ||
210 | +} | ||
211 | + | ||
212 | +// 移除文件服务 | ||
213 | +func (fileService *FileService) RemoveFile(removeFileCommand *command.RemoveFileCommand) (interface{}, error) { | ||
214 | + if err := removeFileCommand.ValidateCommand(); err != nil { | ||
215 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
216 | + } | ||
217 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
218 | + if err != nil { | ||
219 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
220 | + } | ||
221 | + if err := transactionContext.StartTransaction(); err != nil { | ||
222 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
223 | + } | ||
224 | + defer func() { | ||
225 | + transactionContext.RollbackTransaction() | ||
226 | + }() | ||
227 | + var fileRepository domain.FileRepository | ||
228 | + if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
229 | + "transactionContext": transactionContext, | ||
230 | + }); err != nil { | ||
231 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
232 | + } else { | ||
233 | + fileRepository = value | ||
234 | + } | ||
235 | + file, err := fileRepository.FindOne(map[string]interface{}{"fileId": removeFileCommand.FileId}) | ||
236 | + if err != nil { | ||
237 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
238 | + } | ||
239 | + if file == nil { | ||
240 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeFileCommand.FileId))) | ||
241 | + } | ||
242 | + if file, err := fileRepository.Remove(file); err != nil { | ||
243 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
244 | + } else { | ||
245 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
246 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
247 | + } | ||
248 | + return file, nil | ||
249 | + } | ||
250 | +} | ||
251 | + | ||
252 | +// 更新文件服务 | ||
253 | +func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFileCommand) (interface{}, error) { | ||
254 | + if err := updateFileCommand.ValidateCommand(); err != nil { | ||
255 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
256 | + } | ||
257 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
258 | + if err != nil { | ||
259 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
260 | + } | ||
261 | + if err := transactionContext.StartTransaction(); err != nil { | ||
262 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
263 | + } | ||
264 | + defer func() { | ||
265 | + transactionContext.RollbackTransaction() | ||
266 | + }() | ||
267 | + var fileRepository domain.FileRepository | ||
268 | + if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
269 | + "transactionContext": transactionContext, | ||
270 | + }); err != nil { | ||
271 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
272 | + } else { | ||
273 | + fileRepository = value | ||
274 | + } | ||
275 | + file, err := fileRepository.FindOne(map[string]interface{}{"fileId": updateFileCommand.FileId}) | ||
276 | + if err != nil { | ||
277 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
278 | + } | ||
279 | + if file == nil { | ||
280 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateFileCommand.FileId))) | ||
281 | + } | ||
282 | + if err := file.Update(tool_funs.SimpleStructToMap(updateFileCommand)); err != nil { | ||
283 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
284 | + } | ||
285 | + if file, err := fileRepository.Save(file); err != nil { | ||
286 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
287 | + } else { | ||
288 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
289 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
290 | + } | ||
291 | + return file, nil | ||
292 | + } | ||
293 | +} | ||
294 | + | ||
295 | +func NewFileService(options map[string]interface{}) *FileService { | ||
296 | + newFileService := &FileService{} | ||
297 | + return newFileService | ||
298 | +} |
pkg/application/init.go
0 → 100644
pkg/constant/common.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | +) | ||
6 | + | ||
7 | +var SERVICE_NAME = "character-library-metadata-bastion" | ||
8 | +var SERVICE_ENV = "dev" | ||
9 | +var HTTP_PORT int = 8081 | ||
10 | +var CACHE_PREFIX = "character-library-metadata-bastion-dev" | ||
11 | +var LOG_LEVEL = "debug" | ||
12 | +var LOG_FILE = "app.log" | ||
13 | +var PPROF_ON = true | ||
14 | + | ||
15 | +//天联共创基础模块 | ||
16 | +//var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" | ||
17 | + | ||
18 | +//天联共创用户模块 | ||
19 | +var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com" | ||
20 | + | ||
21 | +//天联共创业务模块 | ||
22 | +//var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com" | ||
23 | + | ||
24 | +var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" | ||
25 | + | ||
26 | +//var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} | ||
27 | + | ||
28 | +//const CUSTOMER_ACCOUNT_DELIMITER = "," | ||
29 | + | ||
30 | +/***** 1.数据传输 *****/ | ||
31 | +//const HeaderCompanyId = "companyId" | ||
32 | +//const HeaderUserId = "userId" | ||
33 | +//const HeaderOrgId = "orgId" | ||
34 | +//const HeaderOrgIds = "orgIds" | ||
35 | + | ||
36 | +func init() { | ||
37 | + LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) | ||
38 | + //ALLIED_CREATION_BASIC_HOST = Configurator.DefaultString("ALLIED_CREATION_BASIC_HOST", ALLIED_CREATION_BASIC_HOST) | ||
39 | + ALLIED_CREATION_USER_HOST = Configurator.DefaultString("ALLIED_CREATION_USER_HOST", ALLIED_CREATION_USER_HOST) | ||
40 | + //ALLIED_CREATION_COOPERATION_HOST = Configurator.DefaultString("ALLIED_CREATION_COOPERATION_HOST", ALLIED_CREATION_COOPERATION_HOST) | ||
41 | + MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) | ||
42 | + SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) | ||
43 | + HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT) | ||
44 | + SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) | ||
45 | + PPROF_ON = Configurator.DefaultBool("PPROF_ON", PPROF_ON) | ||
46 | + CACHE_PREFIX = SERVICE_NAME | ||
47 | +} |
pkg/constant/constant_conf.go
0 → 100644
pkg/constant/constant_env.go
0 → 100644
pkg/constant/kafka.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +var ( | ||
4 | + // kafka 地址 | ||
5 | + KAFKA_HOST = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092" //"106.75.231.90:9092" | ||
6 | + // kafka topic log stash | ||
7 | + TOPIC_LOG_STASH = "go_stash_dev" //"pushMessage" | ||
8 | + // kafka topic up_block_chain | ||
9 | + TOPIC_UP_BLOCK_CHAIN = "allied_creation_message" | ||
10 | + // 是否启用日志收集 (本地不启用) | ||
11 | + ENABLE_KAFKA_LOG = false | ||
12 | +) | ||
13 | + | ||
14 | +func init() { | ||
15 | + KAFKA_HOST = Configurator.DefaultString("KAFKA_HOST", KAFKA_HOST) | ||
16 | + ENABLE_KAFKA_LOG = Configurator.DefaultBool("ENABLE_KAFKA_LOG", ENABLE_KAFKA_LOG) | ||
17 | +} |
pkg/constant/postgresql.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +var POSTGRESQL_DB_NAME = "terms" | ||
4 | +var POSTGRESQL_USER = "postgres" | ||
5 | +var POSTGRESQL_PASSWORD = "123456" | ||
6 | +var POSTGRESQL_HOST = "127.0.0.1" | ||
7 | +var POSTGRESQL_PORT = "5432" | ||
8 | +var DISABLE_CREATE_TABLE = false | ||
9 | +var DISABLE_SQL_GENERATE_PRINT = false | ||
10 | +var DISABLE_SQL_GENERATE_COMMENT = true | ||
11 | + | ||
12 | +func init() { | ||
13 | + POSTGRESQL_HOST = Configurator.DefaultString("POSTGRESQL_HOST", POSTGRESQL_HOST) | ||
14 | + POSTGRESQL_PORT = Configurator.DefaultString("POSTGRESQL_PORT", POSTGRESQL_PORT) | ||
15 | + POSTGRESQL_DB_NAME = Configurator.DefaultString("POSTGRESQL_DB_NAME", POSTGRESQL_DB_NAME) | ||
16 | + POSTGRESQL_USER = Configurator.DefaultString("POSTGRESQL_USER", POSTGRESQL_USER) | ||
17 | + POSTGRESQL_PASSWORD = Configurator.DefaultString("POSTGRESQL_PASSWORD", POSTGRESQL_PASSWORD) | ||
18 | + | ||
19 | + DISABLE_CREATE_TABLE = Configurator.DefaultBool("DISABLE_CREATE_TABLE", DISABLE_CREATE_TABLE) | ||
20 | + DISABLE_SQL_GENERATE_PRINT = Configurator.DefaultBool("DISABLE_SQL_GENERATE_PRINT", DISABLE_SQL_GENERATE_PRINT) | ||
21 | +} |
pkg/constant/redis.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +var ( | ||
4 | + REDIS_HOST = "127.0.0.1" | ||
5 | + REDIS_PORT = "6379" | ||
6 | + REDIS_AUTH = "" | ||
7 | + REDIS_ADDRESS = "" | ||
8 | + | ||
9 | + // 是否关闭仓储层缓存 | ||
10 | + ENABLE_REPOSITORY_CACHE = true | ||
11 | + // 缓存过期时间 单位秒 | ||
12 | + REPOSITORY_CACHE_EXPIRE = 30 * 60 | ||
13 | + // redis 考勤机打卡消息队列 | ||
14 | + REDIS_ZKTECO_KEY = "allied-creation-zkteco" | ||
15 | + // redis 车间数据消息队列 | ||
16 | + REDIS_WORKSHOP_KEY = "allied-creation-workshop" | ||
17 | +) | ||
18 | + | ||
19 | +func init() { | ||
20 | + REDIS_HOST = Configurator.DefaultString("REDIS_HOST", REDIS_HOST) | ||
21 | + REDIS_PORT = Configurator.DefaultString("REDIS_PORT", REDIS_PORT) | ||
22 | + REDIS_AUTH = Configurator.DefaultString("REDIS_AUTH", REDIS_AUTH) | ||
23 | + ENABLE_REPOSITORY_CACHE = Configurator.DefaultBool("ENABLE_REPOSITORY_CACHE", ENABLE_REPOSITORY_CACHE) | ||
24 | + REDIS_ADDRESS = REDIS_HOST + ":" + REDIS_PORT | ||
25 | +} |
pkg/domain/field.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// Field 字段 | ||
4 | +type Field struct { | ||
5 | + // 字段Id | ||
6 | + FieldId int `json:"fieldId"` | ||
7 | + // 索引序号 | ||
8 | + Index int `json:"index"` | ||
9 | + // 名称 | ||
10 | + Name string `json:"name"` | ||
11 | + // 对应数据库名称 | ||
12 | + SQLName string `json:"sqlName"` | ||
13 | + // 对应数据库类型 | ||
14 | + SQLType string `json:"sqlType"` | ||
15 | + // 描述 | ||
16 | + Description string `json:"description"` | ||
17 | + // 标识 1:主表字段 2:手动添加 | ||
18 | + Flag int `json:"flag"` | ||
19 | +} |
pkg/domain/file.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// File 文件 | ||
6 | +type File struct { | ||
7 | + // 文件ID | ||
8 | + FileId int `json:"fileId"` | ||
9 | + // 文件类型 | ||
10 | + FileType string `json:"fileType"` | ||
11 | + // 文件信息 | ||
12 | + FileInfo *FileInfo `json:"fileInfo"` | ||
13 | + // 源文件Id(FileType为TemporaryFile或VerifiedFile时有值) | ||
14 | + SourceFileId string `json:"sourceFileId"` | ||
15 | + // 操作人 | ||
16 | + Operator string `json:"operator"` | ||
17 | + // 创建时间 | ||
18 | + CreatedAt time.Time `json:"createdAt"` | ||
19 | + // 更新时间 | ||
20 | + UpdatedAt time.Time `json:"updatedAt"` | ||
21 | + // 删除时间 | ||
22 | + DeletedAt time.Time `json:"deletedAt"` | ||
23 | + // 版本 | ||
24 | + Version int `json:"version"` | ||
25 | +} | ||
26 | + | ||
27 | +type FileRepository interface { | ||
28 | + Save(file *File) (*File, error) | ||
29 | + Remove(file *File) (*File, error) | ||
30 | + FindOne(queryOptions map[string]interface{}) (*File, error) | ||
31 | + Find(queryOptions map[string]interface{}) (int64, []*File, error) | ||
32 | +} | ||
33 | + | ||
34 | +func (file *File) Identify() interface{} { | ||
35 | + if file.FileId == 0 { | ||
36 | + return nil | ||
37 | + } | ||
38 | + return file.FileId | ||
39 | +} | ||
40 | + | ||
41 | +func (file *File) Update(data map[string]interface{}) error { | ||
42 | + return nil | ||
43 | +} |
pkg/domain/file_info.go
0 → 100644
pkg/domain/log.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// Log 日志 | ||
6 | +type Log struct { | ||
7 | + // 日志ID | ||
8 | + LogId int `json:"logId"` | ||
9 | + // 日志类型 1.校验步骤 2.常规日志 | ||
10 | + LogType int `json:"logType"` | ||
11 | + // 源数据ID | ||
12 | + SourceId int `json:"sourceId"` | ||
13 | + // 日志内容 | ||
14 | + Entry *LogEntry `json:"entry"` | ||
15 | + // 创建时间 | ||
16 | + CreatedAt time.Time `json:"createdAt"` | ||
17 | +} | ||
18 | + | ||
19 | +type LogRepository interface { | ||
20 | + Save(log *Log) (*Log, error) | ||
21 | + Remove(log *Log) (*Log, error) | ||
22 | + FindOne(queryOptions map[string]interface{}) (*Log, error) | ||
23 | + Find(queryOptions map[string]interface{}) (int64, []*Log, error) | ||
24 | +} | ||
25 | + | ||
26 | +func (log *Log) Identify() interface{} { | ||
27 | + if log.LogId == 0 { | ||
28 | + return nil | ||
29 | + } | ||
30 | + return log.LogId | ||
31 | +} | ||
32 | + | ||
33 | +func (log *Log) Update(data map[string]interface{}) error { | ||
34 | + | ||
35 | + return nil | ||
36 | +} |
pkg/domain/log_entry.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// LogEntry 日志内容 | ||
4 | +type LogEntry struct { | ||
5 | + // 对象名称 数据表名 / 文件名 | ||
6 | + ObjectName string `json:"objectName"` | ||
7 | + // 对象类型 1.主表 2.分表 3.副表 4.源文件 5.校验文件 | ||
8 | + ObjectType string `json:"objectType"` | ||
9 | + // 操作类型 1.主表生成 2.主表拆分 3.数据导入 4.分表生成 5.表复制 6.编辑记录 7.文件上传 8.文件校验 | ||
10 | + OperationType string `json:"operationType"` | ||
11 | + // 日志内容 | ||
12 | + Content string `json:"content"` | ||
13 | + // 操作人名称 | ||
14 | + OperatorName string `json:"operatorName"` | ||
15 | +} |
pkg/domain/table.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// Table 表 | ||
6 | +type Table struct { | ||
7 | + // 表Id | ||
8 | + TableId int `json:"tableId"` | ||
9 | + // 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表 | ||
10 | + TableType string `json:"tableType"` | ||
11 | + // 名称 | ||
12 | + Name string `json:"name"` | ||
13 | + // 对应数据库名称 | ||
14 | + SQLName string `json:"sQLName"` | ||
15 | + // 父级ID | ||
16 | + ParentId int64 `json:"parentId,string"` | ||
17 | + // 数据字段序号 | ||
18 | + DataFieldIndex int `json:"dataFieldIndex"` | ||
19 | + // 主键字段 | ||
20 | + PK string `json:"pK"` | ||
21 | + // 数据列 | ||
22 | + DataFields string `json:"dataFields"` | ||
23 | + // 手动添加的列 | ||
24 | + ManualFields string `json:"manualFields"` | ||
25 | + // 创建时间 | ||
26 | + CreatedAt time.Time `json:"createdAt"` | ||
27 | + // 更新时间 | ||
28 | + UpdatedAt time.Time `json:"updatedAt"` | ||
29 | + // 删除时间 | ||
30 | + DeletedAt time.Time `json:"deletedAt"` | ||
31 | + // 版本 | ||
32 | + Version int `json:"version"` | ||
33 | +} | ||
34 | + | ||
35 | +type TableRepository interface { | ||
36 | + Save(table *Table) (*Table, error) | ||
37 | + Remove(table *Table) (*Table, error) | ||
38 | + FindOne(queryOptions map[string]interface{}) (*Table, error) | ||
39 | + Find(queryOptions map[string]interface{}) (int64, []*Table, error) | ||
40 | +} | ||
41 | + | ||
42 | +func (table *Table) Identify() interface{} { | ||
43 | + if table.TableId == 0 { | ||
44 | + return nil | ||
45 | + } | ||
46 | + return table.TableId | ||
47 | +} | ||
48 | + | ||
49 | +func (table *Table) Update(data map[string]interface{}) error { | ||
50 | + return nil | ||
51 | +} |
pkg/infrastructure/pg/init.go
0 → 100644
1 | +package pg | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + "github.com/go-pg/pg/v10/orm" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
8 | + | ||
9 | + //_ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | ||
10 | + "github.com/linmadan/egglib-go/persistent/pg/comment" | ||
11 | + "github.com/linmadan/egglib-go/persistent/pg/hooks" | ||
12 | +) | ||
13 | + | ||
14 | +var DB *pg.DB | ||
15 | + | ||
16 | +func init() { | ||
17 | + DB = pg.Connect(&pg.Options{ | ||
18 | + User: constant.POSTGRESQL_USER, | ||
19 | + Password: constant.POSTGRESQL_PASSWORD, | ||
20 | + Database: constant.POSTGRESQL_DB_NAME, | ||
21 | + Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT), | ||
22 | + }) | ||
23 | + if !constant.DISABLE_SQL_GENERATE_PRINT { | ||
24 | + DB.AddQueryHook(hooks.SqlGeneratePrintHook{}) | ||
25 | + } | ||
26 | + if !constant.DISABLE_CREATE_TABLE { | ||
27 | + for _, model := range []interface{}{} { | ||
28 | + err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | ||
29 | + Temp: false, | ||
30 | + IfNotExists: true, | ||
31 | + FKConstraints: true, | ||
32 | + }) | ||
33 | + if err != nil { | ||
34 | + panic(err) | ||
35 | + } | ||
36 | + comment.AddComments(DB, model) | ||
37 | + } | ||
38 | + } | ||
39 | +} |
pkg/infrastructure/pg/models/file.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type File struct { | ||
9 | + tableName string `comment:"文件" pg:"metadata.files,alias:file"` | ||
10 | + // 文件ID | ||
11 | + FileId int `comment:"文件ID" pg:"pk:file_id"` | ||
12 | + // 文件类型 | ||
13 | + FileType string `comment:"文件类型"` | ||
14 | + // 文件信息 | ||
15 | + FileInfo *domain.FileInfo `comment:"文件信息"` | ||
16 | + // 源文件Id(FileType为TemporaryFile或VerifiedFile时有值) | ||
17 | + SourceFileId string `comment:"源文件Id(FileType为TemporaryFile或VerifiedFile时有值)"` | ||
18 | + // 操作人 | ||
19 | + Operator string `comment:"操作人"` | ||
20 | + // 创建时间 | ||
21 | + CreatedAt time.Time `comment:"创建时间"` | ||
22 | + // 更新时间 | ||
23 | + UpdatedAt time.Time `comment:"更新时间"` | ||
24 | + // 删除时间 | ||
25 | + DeletedAt time.Time `comment:"删除时间"` | ||
26 | + // 版本 | ||
27 | + Version int `comment:"版本"` | ||
28 | +} |
pkg/infrastructure/pg/models/log.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type Log struct { | ||
9 | + tableName string `comment:"日志" pg:"metadata.logs,alias:log"` | ||
10 | + // 日志ID | ||
11 | + LogId int `comment:"日志ID" pg:"pk:log_id"` | ||
12 | + // 日志类型 1.校验步骤 2.常规日志 | ||
13 | + LogType int `comment:"日志类型 1.校验步骤 2.常规日志"` | ||
14 | + // 源数据ID | ||
15 | + SourceId int `comment:"源数据ID"` | ||
16 | + // 日志内容 | ||
17 | + Entry *domain.LogEntry `comment:"日志内容"` | ||
18 | + // 创建时间 | ||
19 | + CreatedAt time.Time `comment:"创建时间"` | ||
20 | +} |
pkg/infrastructure/pg/models/table.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +type Table struct { | ||
6 | + tableName string `comment:"表" pg:"metadata.tables,alias:table"` | ||
7 | + // 表Id | ||
8 | + TableId int `comment:"表Id" pg:"pk:table_id"` | ||
9 | + // 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表 | ||
10 | + TableType string `comment:"表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表"` | ||
11 | + // 名称 | ||
12 | + Name string `comment:"名称"` | ||
13 | + // 对应数据库名称 | ||
14 | + SQLName string `comment:"对应数据库名称"` | ||
15 | + // 父级ID | ||
16 | + ParentId int64 `comment:"父级ID"` | ||
17 | + // 数据字段序号 | ||
18 | + DataFieldIndex int `comment:"数据字段序号"` | ||
19 | + // 主键字段 | ||
20 | + PK string `comment:"主键字段"` | ||
21 | + // 数据列 | ||
22 | + DataFields string `comment:"数据列"` | ||
23 | + // 手动添加的列 | ||
24 | + ManualFields string `comment:"手动添加的列"` | ||
25 | + // 创建时间 | ||
26 | + CreatedAt time.Time `comment:"创建时间"` | ||
27 | + // 更新时间 | ||
28 | + UpdatedAt time.Time `comment:"更新时间"` | ||
29 | + // 删除时间 | ||
30 | + DeletedAt time.Time `comment:"删除时间"` | ||
31 | + // 版本 | ||
32 | + Version int `comment:"版本"` | ||
33 | +} |
pkg/infrastructure/pg/transform/file.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToFileDomainModelFromPgModels(fileModel *models.File) (*domain.File, error) { | ||
9 | + return &domain.File{ | ||
10 | + FileId: fileModel.FileId, | ||
11 | + FileType: fileModel.FileType, | ||
12 | + FileInfo: fileModel.FileInfo, | ||
13 | + SourceFileId: fileModel.SourceFileId, | ||
14 | + Operator: fileModel.Operator, | ||
15 | + CreatedAt: fileModel.CreatedAt, | ||
16 | + UpdatedAt: fileModel.UpdatedAt, | ||
17 | + DeletedAt: fileModel.DeletedAt, | ||
18 | + Version: fileModel.Version, | ||
19 | + }, nil | ||
20 | +} |
pkg/infrastructure/pg/transform/log.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToLogDomainModelFromPgModels(logModel *models.Log) (*domain.Log, error) { | ||
9 | + return &domain.Log{ | ||
10 | + LogId: logModel.LogId, | ||
11 | + LogType: logModel.LogType, | ||
12 | + SourceId: logModel.SourceId, | ||
13 | + Entry: logModel.Entry, | ||
14 | + CreatedAt: logModel.CreatedAt, | ||
15 | + }, nil | ||
16 | +} |
pkg/infrastructure/pg/transform/table.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToTableDomainModelFromPgModels(tableModel *models.Table) (*domain.Table, error) { | ||
9 | + return &domain.Table{ | ||
10 | + TableId: tableModel.TableId, | ||
11 | + TableType: tableModel.TableType, | ||
12 | + Name: tableModel.Name, | ||
13 | + SQLName: tableModel.SQLName, | ||
14 | + ParentId: tableModel.ParentId, | ||
15 | + DataFieldIndex: tableModel.DataFieldIndex, | ||
16 | + PK: tableModel.PK, | ||
17 | + DataFields: tableModel.DataFields, | ||
18 | + ManualFields: tableModel.ManualFields, | ||
19 | + CreatedAt: tableModel.CreatedAt, | ||
20 | + UpdatedAt: tableModel.UpdatedAt, | ||
21 | + DeletedAt: tableModel.DeletedAt, | ||
22 | + Version: tableModel.Version, | ||
23 | + }, nil | ||
24 | +} |
pkg/infrastructure/redis/redis.go
0 → 100644
1 | +package redis | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-redis/redis" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
7 | +) | ||
8 | + | ||
9 | +var clientRedis *redis.Client | ||
10 | + | ||
11 | +func InitRedis() *redis.Client { | ||
12 | + options := redis.Options{ | ||
13 | + Network: "tcp", | ||
14 | + Addr: fmt.Sprintf("%s:%s", constant.REDIS_HOST, constant.REDIS_PORT), | ||
15 | + Dialer: nil, | ||
16 | + OnConnect: nil, | ||
17 | + Password: "", | ||
18 | + DB: 0, | ||
19 | + MaxRetries: 0, | ||
20 | + MinRetryBackoff: 0, | ||
21 | + MaxRetryBackoff: 0, | ||
22 | + DialTimeout: 0, | ||
23 | + ReadTimeout: 0, | ||
24 | + WriteTimeout: 0, | ||
25 | + PoolSize: 0, | ||
26 | + MinIdleConns: 0, | ||
27 | + MaxConnAge: 0, | ||
28 | + PoolTimeout: 0, | ||
29 | + IdleTimeout: 0, | ||
30 | + IdleCheckFrequency: 0, | ||
31 | + TLSConfig: nil, | ||
32 | + } | ||
33 | + // 新建一个client | ||
34 | + clientRedis = redis.NewClient(&options) | ||
35 | + pong, err := clientRedis.Ping().Result() | ||
36 | + if err != nil { | ||
37 | + e := fmt.Errorf("redis 连接失败,%s,%w", pong, err) | ||
38 | + panic(e) | ||
39 | + } | ||
40 | + return clientRedis | ||
41 | +} | ||
42 | + | ||
43 | +func GetRedis() *redis.Client { | ||
44 | + return clientRedis | ||
45 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type FileRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *FileRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *FileRepository) Save(file *domain.File) (*domain.File, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "file_id", | ||
30 | + "file_type", | ||
31 | + "file_info", | ||
32 | + "source_file_id", | ||
33 | + "operator", | ||
34 | + "created_at", | ||
35 | + "updated_at", | ||
36 | + "deleted_at", | ||
37 | + "version", | ||
38 | + } | ||
39 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "file_id", "deleted_at")) | ||
40 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "file_id", "deleted_at")) | ||
41 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
42 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "file_id", "deleted_at") | ||
43 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
44 | + tx := repository.transactionContext.PgTx | ||
45 | + if file.Identify() == nil { | ||
46 | + if _, err := tx.QueryOne( | ||
47 | + pg.Scan( | ||
48 | + &file.FileId, | ||
49 | + &file.FileType, | ||
50 | + &file.FileInfo, | ||
51 | + &file.SourceFileId, | ||
52 | + &file.Operator, | ||
53 | + &file.CreatedAt, | ||
54 | + &file.UpdatedAt, | ||
55 | + &file.DeletedAt, | ||
56 | + &file.Version, | ||
57 | + ), | ||
58 | + fmt.Sprintf("INSERT INTO metadata.files (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
59 | + file.FileId, | ||
60 | + file.FileType, | ||
61 | + file.FileInfo, | ||
62 | + file.SourceFileId, | ||
63 | + file.Operator, | ||
64 | + file.CreatedAt, | ||
65 | + file.UpdatedAt, | ||
66 | + file.Version, | ||
67 | + ); err != nil { | ||
68 | + return file, err | ||
69 | + } | ||
70 | + } else { | ||
71 | + if _, err := tx.QueryOne( | ||
72 | + pg.Scan( | ||
73 | + &file.FileId, | ||
74 | + &file.FileType, | ||
75 | + &file.FileInfo, | ||
76 | + &file.SourceFileId, | ||
77 | + &file.Operator, | ||
78 | + &file.CreatedAt, | ||
79 | + &file.UpdatedAt, | ||
80 | + &file.DeletedAt, | ||
81 | + &file.Version, | ||
82 | + ), | ||
83 | + fmt.Sprintf("UPDATE metadata.files SET %s WHERE file_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
84 | + file.FileId, | ||
85 | + file.FileType, | ||
86 | + file.FileInfo, | ||
87 | + file.SourceFileId, | ||
88 | + file.Operator, | ||
89 | + file.CreatedAt, | ||
90 | + file.UpdatedAt, | ||
91 | + file.DeletedAt, | ||
92 | + file.Version, | ||
93 | + file.Identify(), | ||
94 | + ); err != nil { | ||
95 | + return file, err | ||
96 | + } | ||
97 | + } | ||
98 | + return file, nil | ||
99 | +} | ||
100 | +func (repository *FileRepository) Remove(file *domain.File) (*domain.File, error) { | ||
101 | + tx := repository.transactionContext.PgTx | ||
102 | + fileModel := new(models.File) | ||
103 | + fileModel.FileId = file.Identify().(int) | ||
104 | + if _, err := tx.Model(fileModel).WherePK().Delete(); err != nil { | ||
105 | + return file, err | ||
106 | + } | ||
107 | + return file, nil | ||
108 | +} | ||
109 | +func (repository *FileRepository) FindOne(queryOptions map[string]interface{}) (*domain.File, error) { | ||
110 | + tx := repository.transactionContext.PgTx | ||
111 | + fileModel := new(models.File) | ||
112 | + query := sqlbuilder.BuildQuery(tx.Model(fileModel), queryOptions) | ||
113 | + query.SetWhereByQueryOption("file.file_id = ?", "fileId") | ||
114 | + if err := query.First(); err != nil { | ||
115 | + if err.Error() == "pg: no rows in result set" { | ||
116 | + return nil, fmt.Errorf("没有此资源") | ||
117 | + } else { | ||
118 | + return nil, err | ||
119 | + } | ||
120 | + } | ||
121 | + if fileModel.FileId == 0 { | ||
122 | + return nil, nil | ||
123 | + } else { | ||
124 | + return transform.TransformToFileDomainModelFromPgModels(fileModel) | ||
125 | + } | ||
126 | +} | ||
127 | +func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.File, error) { | ||
128 | + tx := repository.transactionContext.PgTx | ||
129 | + var fileModels []*models.File | ||
130 | + files := make([]*domain.File, 0) | ||
131 | + query := sqlbuilder.BuildQuery(tx.Model(&fileModels), queryOptions) | ||
132 | + query.SetOffsetAndLimit(20) | ||
133 | + query.SetOrderDirect("file_id", "DESC") | ||
134 | + if count, err := query.SelectAndCount(); err != nil { | ||
135 | + return 0, files, err | ||
136 | + } else { | ||
137 | + for _, fileModel := range fileModels { | ||
138 | + if file, err := transform.TransformToFileDomainModelFromPgModels(fileModel); err != nil { | ||
139 | + return 0, files, err | ||
140 | + } else { | ||
141 | + files = append(files, file) | ||
142 | + } | ||
143 | + } | ||
144 | + return int64(count), files, nil | ||
145 | + } | ||
146 | +} | ||
147 | +func NewFileRepository(transactionContext *pgTransaction.TransactionContext) (*FileRepository, error) { | ||
148 | + if transactionContext == nil { | ||
149 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
150 | + } else { | ||
151 | + return &FileRepository{ | ||
152 | + transactionContext: transactionContext, | ||
153 | + }, nil | ||
154 | + } | ||
155 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type LogRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *LogRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *LogRepository) Save(log *domain.Log) (*domain.Log, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "log_id", | ||
30 | + "log_type", | ||
31 | + "source_id", | ||
32 | + "entry", | ||
33 | + "created_at", | ||
34 | + } | ||
35 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "log_id")) | ||
36 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "log_id")) | ||
37 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
38 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "log_id") | ||
39 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
40 | + tx := repository.transactionContext.PgTx | ||
41 | + if log.Identify() == nil { | ||
42 | + if _, err := tx.QueryOne( | ||
43 | + pg.Scan( | ||
44 | + &log.LogId, | ||
45 | + &log.LogType, | ||
46 | + &log.SourceId, | ||
47 | + &log.Entry, | ||
48 | + &log.CreatedAt, | ||
49 | + ), | ||
50 | + fmt.Sprintf("INSERT INTO metadata.logs (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
51 | + //log.LogId, | ||
52 | + log.LogType, | ||
53 | + log.SourceId, | ||
54 | + log.Entry, | ||
55 | + log.CreatedAt, | ||
56 | + ); err != nil { | ||
57 | + return log, err | ||
58 | + } | ||
59 | + } else { | ||
60 | + if _, err := tx.QueryOne( | ||
61 | + pg.Scan( | ||
62 | + &log.LogId, | ||
63 | + &log.LogType, | ||
64 | + &log.SourceId, | ||
65 | + &log.Entry, | ||
66 | + &log.CreatedAt, | ||
67 | + ), | ||
68 | + fmt.Sprintf("UPDATE metadata.logs SET %s WHERE log_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
69 | + //log.LogId, | ||
70 | + log.LogType, | ||
71 | + log.SourceId, | ||
72 | + log.Entry, | ||
73 | + log.CreatedAt, | ||
74 | + log.Identify(), | ||
75 | + ); err != nil { | ||
76 | + return log, err | ||
77 | + } | ||
78 | + } | ||
79 | + return log, nil | ||
80 | +} | ||
81 | +func (repository *LogRepository) Remove(log *domain.Log) (*domain.Log, error) { | ||
82 | + tx := repository.transactionContext.PgTx | ||
83 | + logModel := new(models.Log) | ||
84 | + logModel.LogId = log.Identify().(int) | ||
85 | + if _, err := tx.Model(logModel).WherePK().Delete(); err != nil { | ||
86 | + return log, err | ||
87 | + } | ||
88 | + return log, nil | ||
89 | +} | ||
90 | +func (repository *LogRepository) FindOne(queryOptions map[string]interface{}) (*domain.Log, error) { | ||
91 | + tx := repository.transactionContext.PgTx | ||
92 | + logModel := new(models.Log) | ||
93 | + query := sqlbuilder.BuildQuery(tx.Model(logModel), queryOptions) | ||
94 | + query.SetWhereByQueryOption("log.log_id = ?", "logId") | ||
95 | + if err := query.First(); err != nil { | ||
96 | + if err.Error() == "pg: no rows in result set" { | ||
97 | + return nil, fmt.Errorf("没有此资源") | ||
98 | + } else { | ||
99 | + return nil, err | ||
100 | + } | ||
101 | + } | ||
102 | + if logModel.LogId == 0 { | ||
103 | + return nil, nil | ||
104 | + } else { | ||
105 | + return transform.TransformToLogDomainModelFromPgModels(logModel) | ||
106 | + } | ||
107 | +} | ||
108 | +func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Log, error) { | ||
109 | + tx := repository.transactionContext.PgTx | ||
110 | + var logModels []*models.Log | ||
111 | + logs := make([]*domain.Log, 0) | ||
112 | + query := sqlbuilder.BuildQuery(tx.Model(&logModels), queryOptions) | ||
113 | + query.SetOffsetAndLimit(20) | ||
114 | + query.SetOrderDirect("log_id", "DESC") | ||
115 | + if count, err := query.SelectAndCount(); err != nil { | ||
116 | + return 0, logs, err | ||
117 | + } else { | ||
118 | + for _, logModel := range logModels { | ||
119 | + if log, err := transform.TransformToLogDomainModelFromPgModels(logModel); err != nil { | ||
120 | + return 0, logs, err | ||
121 | + } else { | ||
122 | + logs = append(logs, log) | ||
123 | + } | ||
124 | + } | ||
125 | + return int64(count), logs, nil | ||
126 | + } | ||
127 | +} | ||
128 | +func NewLogRepository(transactionContext *pgTransaction.TransactionContext) (*LogRepository, error) { | ||
129 | + if transactionContext == nil { | ||
130 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
131 | + } else { | ||
132 | + return &LogRepository{ | ||
133 | + transactionContext: transactionContext, | ||
134 | + }, nil | ||
135 | + } | ||
136 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type TableRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *TableRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *TableRepository) Save(table *domain.Table) (*domain.Table, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "table_id", | ||
30 | + "table_type", | ||
31 | + "name", | ||
32 | + "sql_name", | ||
33 | + "parent_id", | ||
34 | + "data_field_index", | ||
35 | + "pk", | ||
36 | + "data_fields", | ||
37 | + "manual_fields", | ||
38 | + "created_at", | ||
39 | + "updated_at", | ||
40 | + "deleted_at", | ||
41 | + "version", | ||
42 | + } | ||
43 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
44 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
45 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
46 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "table_id") | ||
47 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
48 | + tx := repository.transactionContext.PgTx | ||
49 | + if table.Identify() == nil { | ||
50 | + if _, err := tx.QueryOne( | ||
51 | + pg.Scan( | ||
52 | + &table.TableId, | ||
53 | + &table.TableType, | ||
54 | + &table.Name, | ||
55 | + &table.SQLName, | ||
56 | + &table.ParentId, | ||
57 | + &table.DataFieldIndex, | ||
58 | + &table.PK, | ||
59 | + &table.DataFields, | ||
60 | + &table.ManualFields, | ||
61 | + &table.CreatedAt, | ||
62 | + &table.UpdatedAt, | ||
63 | + &table.DeletedAt, | ||
64 | + &table.Version, | ||
65 | + ), | ||
66 | + fmt.Sprintf("INSERT INTO metadata.tables (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
67 | + table.TableId, | ||
68 | + table.TableType, | ||
69 | + table.Name, | ||
70 | + table.SQLName, | ||
71 | + table.ParentId, | ||
72 | + table.DataFieldIndex, | ||
73 | + table.PK, | ||
74 | + table.DataFields, | ||
75 | + table.ManualFields, | ||
76 | + table.CreatedAt, | ||
77 | + table.UpdatedAt, | ||
78 | + table.DeletedAt, | ||
79 | + table.Version, | ||
80 | + ); err != nil { | ||
81 | + return table, err | ||
82 | + } | ||
83 | + } else { | ||
84 | + if _, err := tx.QueryOne( | ||
85 | + pg.Scan( | ||
86 | + &table.TableId, | ||
87 | + &table.TableType, | ||
88 | + &table.Name, | ||
89 | + &table.SQLName, | ||
90 | + &table.ParentId, | ||
91 | + &table.DataFieldIndex, | ||
92 | + &table.PK, | ||
93 | + &table.DataFields, | ||
94 | + &table.ManualFields, | ||
95 | + &table.CreatedAt, | ||
96 | + &table.UpdatedAt, | ||
97 | + &table.DeletedAt, | ||
98 | + &table.Version, | ||
99 | + ), | ||
100 | + fmt.Sprintf("UPDATE metadata.tables SET %s WHERE table_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
101 | + table.TableId, | ||
102 | + table.TableType, | ||
103 | + table.Name, | ||
104 | + table.SQLName, | ||
105 | + table.ParentId, | ||
106 | + table.DataFieldIndex, | ||
107 | + table.PK, | ||
108 | + table.DataFields, | ||
109 | + table.ManualFields, | ||
110 | + table.CreatedAt, | ||
111 | + table.UpdatedAt, | ||
112 | + table.DeletedAt, | ||
113 | + table.Version, | ||
114 | + table.Identify(), | ||
115 | + ); err != nil { | ||
116 | + return table, err | ||
117 | + } | ||
118 | + } | ||
119 | + return table, nil | ||
120 | +} | ||
121 | +func (repository *TableRepository) Remove(table *domain.Table) (*domain.Table, error) { | ||
122 | + tx := repository.transactionContext.PgTx | ||
123 | + tableModel := new(models.Table) | ||
124 | + tableModel.TableId = table.Identify().(int) | ||
125 | + if _, err := tx.Model(tableModel).WherePK().Delete(); err != nil { | ||
126 | + return table, err | ||
127 | + } | ||
128 | + return table, nil | ||
129 | +} | ||
130 | +func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) (*domain.Table, error) { | ||
131 | + tx := repository.transactionContext.PgTx | ||
132 | + tableModel := new(models.Table) | ||
133 | + query := sqlbuilder.BuildQuery(tx.Model(tableModel), queryOptions) | ||
134 | + query.SetWhereByQueryOption("table.table_id = ?", "tableId") | ||
135 | + if err := query.First(); err != nil { | ||
136 | + if err.Error() == "pg: no rows in result set" { | ||
137 | + return nil, fmt.Errorf("没有此资源") | ||
138 | + } else { | ||
139 | + return nil, err | ||
140 | + } | ||
141 | + } | ||
142 | + if tableModel.TableId == 0 { | ||
143 | + return nil, nil | ||
144 | + } else { | ||
145 | + return transform.TransformToTableDomainModelFromPgModels(tableModel) | ||
146 | + } | ||
147 | +} | ||
148 | +func (repository *TableRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Table, error) { | ||
149 | + tx := repository.transactionContext.PgTx | ||
150 | + var tableModels []*models.Table | ||
151 | + tables := make([]*domain.Table, 0) | ||
152 | + query := sqlbuilder.BuildQuery(tx.Model(&tableModels), queryOptions) | ||
153 | + query.SetOffsetAndLimit(20) | ||
154 | + query.SetOrderDirect("table_id", "DESC") | ||
155 | + if count, err := query.SelectAndCount(); err != nil { | ||
156 | + return 0, tables, err | ||
157 | + } else { | ||
158 | + for _, tableModel := range tableModels { | ||
159 | + if table, err := transform.TransformToTableDomainModelFromPgModels(tableModel); err != nil { | ||
160 | + return 0, tables, err | ||
161 | + } else { | ||
162 | + tables = append(tables, table) | ||
163 | + } | ||
164 | + } | ||
165 | + return int64(count), tables, nil | ||
166 | + } | ||
167 | +} | ||
168 | +func NewTableRepository(transactionContext *pgTransaction.TransactionContext) (*TableRepository, error) { | ||
169 | + if transactionContext == nil { | ||
170 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
171 | + } else { | ||
172 | + return &TableRepository{ | ||
173 | + transactionContext: transactionContext, | ||
174 | + }, nil | ||
175 | + } | ||
176 | +} |
pkg/infrastructure/utils/config.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/core/config" | ||
5 | + "github.com/beego/beego/v2/server/web" | ||
6 | + "os" | ||
7 | + "strconv" | ||
8 | +) | ||
9 | + | ||
10 | +type Configurator interface { | ||
11 | + DefaultString(key string, defaultVal string) string | ||
12 | + DefaultInt(key string, defaultVal int) int | ||
13 | + DefaultInt64(key string, defaultVal int64) int64 | ||
14 | + DefaultBool(key string, defaultVal bool) bool | ||
15 | + DefaultFloat(key string, defaultVal float64) float64 | ||
16 | +} | ||
17 | + | ||
18 | +// EnvConfigurator read config from env param with default value | ||
19 | +type EnvConfigurator struct{} | ||
20 | + | ||
21 | +func (c EnvConfigurator) DefaultString(key string, defaultVal string) string { | ||
22 | + if os.Getenv(key) != "" { | ||
23 | + return os.Getenv(key) | ||
24 | + } | ||
25 | + return defaultVal | ||
26 | +} | ||
27 | +func (c EnvConfigurator) DefaultInt(key string, defaultVal int) int { | ||
28 | + if os.Getenv(key) == "" { | ||
29 | + return defaultVal | ||
30 | + } | ||
31 | + v, err := strconv.Atoi(os.Getenv(key)) | ||
32 | + if err != nil { | ||
33 | + return defaultVal | ||
34 | + } | ||
35 | + return v | ||
36 | +} | ||
37 | +func (c EnvConfigurator) DefaultInt64(key string, defaultVal int64) int64 { | ||
38 | + if os.Getenv(key) == "" { | ||
39 | + return defaultVal | ||
40 | + } | ||
41 | + v, err := strconv.ParseInt(os.Getenv(key), 10, 64) | ||
42 | + if err != nil { | ||
43 | + return defaultVal | ||
44 | + } | ||
45 | + return v | ||
46 | +} | ||
47 | +func (c EnvConfigurator) DefaultBool(key string, defaultVal bool) bool { | ||
48 | + if os.Getenv(key) == "" { | ||
49 | + return defaultVal | ||
50 | + } | ||
51 | + v, err := strconv.ParseBool(os.Getenv(key)) | ||
52 | + if err != nil { | ||
53 | + return defaultVal | ||
54 | + } | ||
55 | + return v | ||
56 | +} | ||
57 | +func (c EnvConfigurator) DefaultFloat(key string, defaultVal float64) float64 { | ||
58 | + if os.Getenv(key) == "" { | ||
59 | + return defaultVal | ||
60 | + } | ||
61 | + v, err := strconv.ParseFloat(os.Getenv(key), 64) | ||
62 | + if err != nil { | ||
63 | + return defaultVal | ||
64 | + } | ||
65 | + return v | ||
66 | +} | ||
67 | + | ||
68 | +// BeegoAppConfigurator read config from beego config file with default value | ||
69 | +type BeegoAppConfigurator struct { | ||
70 | +} | ||
71 | + | ||
72 | +func (c BeegoAppConfigurator) DefaultString(key string, defaultVal string) string { | ||
73 | + return web.AppConfig.DefaultString(key, defaultVal) | ||
74 | +} | ||
75 | +func (c BeegoAppConfigurator) DefaultInt(key string, defaultVal int) int { | ||
76 | + return web.AppConfig.DefaultInt(key, defaultVal) | ||
77 | +} | ||
78 | +func (c BeegoAppConfigurator) DefaultInt64(key string, defaultVal int64) int64 { | ||
79 | + return web.AppConfig.DefaultInt64(key, defaultVal) | ||
80 | +} | ||
81 | +func (c BeegoAppConfigurator) DefaultBool(key string, defaultVal bool) bool { | ||
82 | + return web.AppConfig.DefaultBool(key, defaultVal) | ||
83 | +} | ||
84 | +func (c BeegoAppConfigurator) DefaultFloat(key string, defaultVal float64) float64 { | ||
85 | + return web.AppConfig.DefaultFloat(key, defaultVal) | ||
86 | +} | ||
87 | + | ||
88 | +func NewConfig(adapterName, filename string) Configurator { | ||
89 | + config, err := config.NewConfig(adapterName, filename) | ||
90 | + if err != nil { | ||
91 | + panic(err) | ||
92 | + } | ||
93 | + return config | ||
94 | +} |
pkg/infrastructure/utils/config_test.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/stretchr/testify/assert" | ||
5 | + "os" | ||
6 | + "testing" | ||
7 | +) | ||
8 | + | ||
9 | +func TestEnvConfigurator(t *testing.T) { | ||
10 | + os.Setenv("bool", "true") | ||
11 | + os.Setenv("hello", "world") | ||
12 | + os.Setenv("number", "10") | ||
13 | + | ||
14 | + var config Configurator = EnvConfigurator{} | ||
15 | + assert.Equal(t, "world", config.DefaultString("hello", "w")) | ||
16 | + assert.Equal(t, "w", config.DefaultString("unknown", "w")) | ||
17 | + | ||
18 | + assert.Equal(t, true, config.DefaultBool("bool", false)) | ||
19 | + assert.Equal(t, true, config.DefaultBool("unknown", true)) | ||
20 | + | ||
21 | + assert.Equal(t, 10, config.DefaultInt("number", 5)) | ||
22 | + assert.Equal(t, 5, config.DefaultInt("unknown", 5)) | ||
23 | + | ||
24 | + assert.Equal(t, int64(10), config.DefaultInt64("number", 5)) | ||
25 | + assert.Equal(t, int64(5), config.DefaultInt64("unknown", 5)) | ||
26 | + | ||
27 | + assert.Equal(t, float64(10), config.DefaultFloat("number", 5)) | ||
28 | + assert.Equal(t, float64(5), config.DefaultFloat("unknown", 5)) | ||
29 | +} |
pkg/log/logger.go
0 → 100644
1 | +package log | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/log" | ||
5 | + "github.com/linmadan/egglib-go/log/logrus" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
7 | + "io" | ||
8 | +) | ||
9 | + | ||
10 | +var Logger log.Logger | ||
11 | + | ||
12 | +func init() { | ||
13 | + Logger = logrus.NewLogrusLogger() | ||
14 | + Logger.SetServiceName(constant.SERVICE_NAME) | ||
15 | + Logger.SetLevel(constant.LOG_LEVEL) | ||
16 | +} | ||
17 | + | ||
18 | +func InitLogHook(enableKafka bool, enableBeeLog bool) { | ||
19 | + if enableKafka { | ||
20 | + if w, err := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false); err == nil { | ||
21 | + Logger.AddHook(w) | ||
22 | + } else { | ||
23 | + Logger.Error(err.Error()) | ||
24 | + } | ||
25 | + } | ||
26 | + | ||
27 | + if enableBeeLog { | ||
28 | + if w, err := logrus.NewWrapHook(true, func() (io.Writer, error) { | ||
29 | + return logrus.NewBeegoLogWriter("", `{"filename":"app.log","maxsize":2048000}`) | ||
30 | + }); err == nil { | ||
31 | + Logger.AddHook(w) | ||
32 | + } else { | ||
33 | + Logger.Error(err.Error()) | ||
34 | + } | ||
35 | + } | ||
36 | +} | ||
37 | + | ||
38 | +//var Logger *LogrusLogger | ||
39 | +// | ||
40 | +//func init() { | ||
41 | +// Logger = NewLogrusLogger() | ||
42 | +// Logger.SetServiceName(constant.SERVICE_NAME) | ||
43 | +// Logger.SetLevel(constant.LOG_LEVEL) | ||
44 | +//} |
pkg/log/logrus.go
0 → 100644
1 | +package log | ||
2 | + | ||
3 | +//func init() { | ||
4 | +// logrus.SetFormatter(&logrus.JSONFormatter{}) | ||
5 | +// logrus.SetOutput(os.Stdout) | ||
6 | +// logrus.SetLevel(logrus.WarnLevel) | ||
7 | +//} | ||
8 | +// | ||
9 | +//type LogrusLogger struct { | ||
10 | +// serviceName string | ||
11 | +// logrus *logrus.Logger | ||
12 | +//} | ||
13 | +// | ||
14 | +//func (logger *LogrusLogger) SetServiceName(serviceName string) { | ||
15 | +// logger.serviceName = serviceName | ||
16 | +//} | ||
17 | +// | ||
18 | +//func (logger *LogrusLogger) SetLevel(level string) { | ||
19 | +// switch level { | ||
20 | +// case "trace": | ||
21 | +// logger.logrus.Level = logrus.TraceLevel | ||
22 | +// case "debug": | ||
23 | +// logger.logrus.Level = logrus.DebugLevel | ||
24 | +// case "info": | ||
25 | +// logger.logrus.Level = logrus.InfoLevel | ||
26 | +// case "warn": | ||
27 | +// logger.logrus.Level = logrus.WarnLevel | ||
28 | +// case "error": | ||
29 | +// logger.logrus.Level = logrus.ErrorLevel | ||
30 | +// case "fatal": | ||
31 | +// logger.logrus.Level = logrus.FatalLevel | ||
32 | +// case "panic": | ||
33 | +// logger.logrus.Level = logrus.PanicLevel | ||
34 | +// default: | ||
35 | +// logger.logrus.Level = logrus.DebugLevel | ||
36 | +// } | ||
37 | +//} | ||
38 | +// | ||
39 | +//func (logger *LogrusLogger) AddHook(w io.Writer) { | ||
40 | +// level := logger.logrus.Level | ||
41 | +// var levels []logrus.Level | ||
42 | +// // 默认已经添加了一个当前log level的hook,所以此处 level+1 | ||
43 | +// for i := 0; i <= (int(level)); i++ { | ||
44 | +// levels = append(levels, logrus.Level(i)) | ||
45 | +// } | ||
46 | +// logger.logrus.AddHook(&writer.Hook{ | ||
47 | +// Writer: w, | ||
48 | +// LogLevels: levels, | ||
49 | +// }) | ||
50 | +//} | ||
51 | +// | ||
52 | +//func (logger *LogrusLogger) Trace(msg string, appends ...map[string]interface{}) { | ||
53 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
54 | +// for _, append := range appends { | ||
55 | +// contextLogger = contextLogger.WithFields(append) | ||
56 | +// } | ||
57 | +// contextLogger.Trace(msg) | ||
58 | +//} | ||
59 | +// | ||
60 | +//func (logger *LogrusLogger) Debug(msg string, appends ...map[string]interface{}) { | ||
61 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
62 | +// for _, append := range appends { | ||
63 | +// contextLogger = contextLogger.WithFields(append) | ||
64 | +// } | ||
65 | +// contextLogger.Debug(msg) | ||
66 | +//} | ||
67 | +// | ||
68 | +//func (logger *LogrusLogger) Info(msg string, appends ...map[string]interface{}) { | ||
69 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
70 | +// for _, append := range appends { | ||
71 | +// contextLogger = contextLogger.WithFields(append) | ||
72 | +// } | ||
73 | +// contextLogger.Info(msg) | ||
74 | +//} | ||
75 | +// | ||
76 | +//func (logger *LogrusLogger) Warn(msg string, appends ...map[string]interface{}) { | ||
77 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
78 | +// for _, append := range appends { | ||
79 | +// contextLogger = contextLogger.WithFields(append) | ||
80 | +// } | ||
81 | +// contextLogger.Warn(msg) | ||
82 | +//} | ||
83 | +// | ||
84 | +//func (logger *LogrusLogger) Error(msg string, appends ...map[string]interface{}) { | ||
85 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
86 | +// for _, append := range appends { | ||
87 | +// contextLogger = contextLogger.WithFields(append) | ||
88 | +// } | ||
89 | +// contextLogger.Error(msg) | ||
90 | +//} | ||
91 | +// | ||
92 | +//func (logger *LogrusLogger) Fatal(msg string, appends ...map[string]interface{}) { | ||
93 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
94 | +// for _, append := range appends { | ||
95 | +// contextLogger = contextLogger.WithFields(append) | ||
96 | +// } | ||
97 | +// contextLogger.Fatal(msg) | ||
98 | +//} | ||
99 | +// | ||
100 | +//func (logger *LogrusLogger) Panic(msg string, appends ...map[string]interface{}) { | ||
101 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
102 | +// for _, append := range appends { | ||
103 | +// contextLogger = contextLogger.WithFields(append) | ||
104 | +// } | ||
105 | +// contextLogger.Panic(msg) | ||
106 | +//} | ||
107 | +// | ||
108 | +//func NewLogrusLogger() *LogrusLogger { | ||
109 | +// logger := logrus.New() | ||
110 | +// logger.Formatter = &logrus.JSONFormatter{} | ||
111 | +// logger.Out = os.Stdout | ||
112 | +// return &LogrusLogger{ | ||
113 | +// logrus: logger, | ||
114 | +// } | ||
115 | +//} | ||
116 | +// | ||
117 | +//var _ log.Logger = (*LogrusLogger)(nil) |
pkg/log/logrus_hook.go
0 → 100644
1 | +package log | ||
2 | + | ||
3 | +//import ( | ||
4 | +// "encoding/json" | ||
5 | +// "errors" | ||
6 | +// "fmt" | ||
7 | +// "github.com/beego/beego/v2/core/logs" | ||
8 | +// "io" | ||
9 | +// "sync/atomic" | ||
10 | +//) | ||
11 | +// | ||
12 | +//var errOutOfMaxSize = errors.New("msg size is out of limit ") | ||
13 | +// | ||
14 | +//type BaseHook struct { | ||
15 | +// syncWrite bool | ||
16 | +// msgChan chan []byte | ||
17 | +// maxSize int32 | ||
18 | +// currentSize int32 | ||
19 | +// closeChan chan struct{} | ||
20 | +// w io.Writer | ||
21 | +//} | ||
22 | +// | ||
23 | +//func (b *BaseHook) Write(p []byte) (n int, err error) { | ||
24 | +// if b.syncWrite { | ||
25 | +// return b.w.Write(p) | ||
26 | +// } | ||
27 | +// if b.currentSize >= b.maxSize { | ||
28 | +// fmt.Println(errOutOfMaxSize.Error(), b.currentSize) | ||
29 | +// return 0, errOutOfMaxSize | ||
30 | +// } | ||
31 | +// b.msgChan <- p | ||
32 | +// atomic.AddInt32(&b.currentSize, 1) | ||
33 | +// | ||
34 | +// return len(p), nil | ||
35 | +//} | ||
36 | +// | ||
37 | +//// NewBaseHook | ||
38 | +//// syncWriteFlag 同步写标识 true:同步写 false:异步写 | ||
39 | +//func NewBaseHook(syncWriteFlag bool, internalIo io.WriteCloser) (*BaseHook, error) { | ||
40 | +// writer := &BaseHook{ | ||
41 | +// syncWrite: syncWriteFlag, | ||
42 | +// maxSize: 10000, | ||
43 | +// msgChan: make(chan []byte, 10000), | ||
44 | +// closeChan: make(chan struct{}), | ||
45 | +// w: internalIo, | ||
46 | +// } | ||
47 | +// go writer.ConsumeMsg() | ||
48 | +// return writer, nil | ||
49 | +//} | ||
50 | +// | ||
51 | +//func (b *BaseHook) ConsumeMsg() { | ||
52 | +// for { | ||
53 | +// select { | ||
54 | +// case <-b.closeChan: | ||
55 | +// return | ||
56 | +// case m, ok := <-b.msgChan: | ||
57 | +// if ok { | ||
58 | +// atomic.AddInt32(&b.currentSize, -1) | ||
59 | +// if _, err := b.w.Write(m); err != nil { | ||
60 | +// fmt.Println(err) | ||
61 | +// } | ||
62 | +// } | ||
63 | +// } | ||
64 | +// } | ||
65 | +//} | ||
66 | +// | ||
67 | +//func (b *BaseHook) Close() { | ||
68 | +// close(b.msgChan) | ||
69 | +// b.closeChan <- struct{}{} | ||
70 | +// //b.wc.Close() | ||
71 | +//} | ||
72 | +// | ||
73 | +//type LoggerConfig struct { | ||
74 | +// Level int `json:"level,omitempty"` | ||
75 | +// Filename string `json:"filename,omitempty"` | ||
76 | +// MaxSize int `json:"maxsize,omitempty"` | ||
77 | +// //MaxBackups int `json:"max_backups,omitempty"` | ||
78 | +// //MaxAge int `json:"max_age,omitempty"` | ||
79 | +// //Compress bool `json:"compress,omitempty"` | ||
80 | +// //文件最多保存多少天,默认保存 7 天 | ||
81 | +// //MaxDays int `json:"maxdays"` | ||
82 | +//} | ||
83 | +// | ||
84 | +//type internalLog struct { | ||
85 | +// *logs.BeeLogger | ||
86 | +//} | ||
87 | +// | ||
88 | +//func NewBeegoLogWriter(conf LoggerConfig) io.Writer { | ||
89 | +// logger := logs.GetBeeLogger() | ||
90 | +// logger.SetLevel(conf.Level) | ||
91 | +// logger.EnableFuncCallDepth(true) | ||
92 | +// logger.SetLogFuncCallDepth(2) | ||
93 | +// confByte, _ := json.Marshal(conf) | ||
94 | +// err := logger.SetLogger(logs.AdapterFile, string(confByte)) | ||
95 | +// if err != nil { | ||
96 | +// fmt.Println(err.Error()) | ||
97 | +// } | ||
98 | +// return &internalLog{logger} | ||
99 | +//} | ||
100 | +// | ||
101 | +//func (l *internalLog) Write(p []byte) (n int, err error) { | ||
102 | +// l.Debug(string(p)) | ||
103 | +// return len(p), nil | ||
104 | +//} |
pkg/port/beego/beego.go
0 → 100644
1 | +package beego | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "github.com/linmadan/egglib-go/web/beego/filters" | ||
6 | + "os" | ||
7 | + "strconv" | ||
8 | + | ||
9 | + . "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
10 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/routers" | ||
11 | +) | ||
12 | + | ||
13 | +func init() { | ||
14 | + web.BConfig.AppName = "character-library-metadata-bastion" | ||
15 | + web.BConfig.CopyRequestBody = true | ||
16 | + web.BConfig.RunMode = "dev" | ||
17 | + web.BConfig.Listen.HTTPPort = 8080 | ||
18 | + web.BConfig.Listen.EnableAdmin = false | ||
19 | + web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers" | ||
20 | + if os.Getenv("RUN_MODE") != "" { | ||
21 | + web.BConfig.RunMode = os.Getenv("RUN_MODE") | ||
22 | + } | ||
23 | + if os.Getenv("HTTP_PORT") != "" { | ||
24 | + portStr := os.Getenv("HTTP_PORT") | ||
25 | + if port, err := strconv.Atoi(portStr); err == nil { | ||
26 | + web.BConfig.Listen.HTTPPort = port | ||
27 | + } | ||
28 | + } | ||
29 | + web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) | ||
30 | + web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger)) | ||
31 | + web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) | ||
32 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/service" | ||
8 | +) | ||
9 | + | ||
10 | +type FileController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *FileController) CreateFile() { | ||
15 | + fileService := service.NewFileService(nil) | ||
16 | + createFileCommand := &command.CreateFileCommand{} | ||
17 | + controller.Unmarshal(createFileCommand) | ||
18 | + data, err := fileService.CreateFile(createFileCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *FileController) UpdateFile() { | ||
23 | + fileService := service.NewFileService(nil) | ||
24 | + updateFileCommand := &command.UpdateFileCommand{} | ||
25 | + controller.Unmarshal(updateFileCommand) | ||
26 | + fileId, _ := controller.GetInt(":fileId") | ||
27 | + updateFileCommand.FileId = fileId | ||
28 | + data, err := fileService.UpdateFile(updateFileCommand) | ||
29 | + controller.Response(data, err) | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *FileController) GetFile() { | ||
33 | + fileService := service.NewFileService(nil) | ||
34 | + getFileQuery := &query.GetFileQuery{} | ||
35 | + fileId, _ := controller.GetInt(":fileId") | ||
36 | + getFileQuery.FileId = fileId | ||
37 | + data, err := fileService.GetFile(getFileQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *FileController) RemoveFile() { | ||
42 | + fileService := service.NewFileService(nil) | ||
43 | + removeFileCommand := &command.RemoveFileCommand{} | ||
44 | + controller.Unmarshal(removeFileCommand) | ||
45 | + fileId, _ := controller.GetInt(":fileId") | ||
46 | + removeFileCommand.FileId = fileId | ||
47 | + data, err := fileService.RemoveFile(removeFileCommand) | ||
48 | + controller.Response(data, err) | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *FileController) ListFile() { | ||
52 | + fileService := service.NewFileService(nil) | ||
53 | + listFileQuery := &query.ListFileQuery{} | ||
54 | + offset, _ := controller.GetInt("offset") | ||
55 | + listFileQuery.Offset = offset | ||
56 | + limit, _ := controller.GetInt("limit") | ||
57 | + listFileQuery.Limit = limit | ||
58 | + data, err := fileService.ListFile(listFileQuery) | ||
59 | + controller.Response(data, err) | ||
60 | +} | ||
61 | + | ||
62 | +func (controller *FileController) LoadDataTable() { | ||
63 | + fileService := service.NewFileService(nil) | ||
64 | + loadDataTableCommand := &command.LoadDataTableCommand{} | ||
65 | + controller.Unmarshal(loadDataTableCommand) | ||
66 | + data, err := fileService.LoadDataTable(loadDataTableCommand) | ||
67 | + controller.Response(data, err) | ||
68 | +} | ||
69 | + | ||
70 | +func (controller *FileController) EditDataTable() { | ||
71 | + fileService := service.NewFileService(nil) | ||
72 | + editDataTableCommand := &command.EditDataTableCommand{} | ||
73 | + controller.Unmarshal(editDataTableCommand) | ||
74 | + data, err := fileService.EditDataTable(editDataTableCommand) | ||
75 | + controller.Response(data, err) | ||
76 | +} | ||
77 | + | ||
78 | +func (controller *FileController) FlushDataTable() { | ||
79 | + fileService := service.NewFileService(nil) | ||
80 | + flushDataTableCommand := &command.FlushDataTableCommand{} | ||
81 | + controller.Unmarshal(flushDataTableCommand) | ||
82 | + data, err := fileService.FlushDataTable(flushDataTableCommand) | ||
83 | + controller.Response(data, err) | ||
84 | +} | ||
85 | + | ||
86 | +func (controller *FileController) GenerateMainTable() { | ||
87 | + fileService := service.NewFileService(nil) | ||
88 | + generateMainTableCommand := &command.GenerateMainTableCommand{} | ||
89 | + controller.Unmarshal(generateMainTableCommand) | ||
90 | + data, err := fileService.GenerateMainTable(generateMainTableCommand) | ||
91 | + controller.Response(data, err) | ||
92 | +} |
pkg/port/beego/routers/file_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/bastion/files/", &controllers.FileController{}, "Post:CreateFile") | ||
10 | + web.Router("/bastion/files/:fileId", &controllers.FileController{}, "Put:UpdateFile") | ||
11 | + web.Router("/bastion/files/:fileId", &controllers.FileController{}, "Get:GetFile") | ||
12 | + web.Router("/bastion/files/:fileId", &controllers.FileController{}, "Delete:RemoveFile") | ||
13 | + web.Router("/bastion/files/", &controllers.FileController{}, "Get:ListFile") | ||
14 | + web.Router("/bastion/load-data-table", &controllers.FileController{}, "Post:LoadDataTable") | ||
15 | + web.Router("/bastion/edit-data-table", &controllers.FileController{}, "Post:EditDataTable") | ||
16 | + web.Router("/bastion/flush-data-table", &controllers.FileController{}, "Post:FlushDataTable") | ||
17 | + web.Router("/bastion/generate-main-table", &controllers.FileController{}, "Post:GenerateMainTable") | ||
18 | +} |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("创建文件服务", func() { | ||
13 | + Describe("提交数据创建文件服务", func() { | ||
14 | + Context("提交正确的新文件数据", func() { | ||
15 | + It("返回文件数据", func() { | ||
16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
17 | + body := map[string]interface{}{ | ||
18 | + "name": "string", | ||
19 | + "url": "string", | ||
20 | + "fileSize": "int", | ||
21 | + } | ||
22 | + httpExpect.POST("/files/"). | ||
23 | + WithJSON(body). | ||
24 | + Expect(). | ||
25 | + Status(http.StatusOK). | ||
26 | + JSON(). | ||
27 | + Object(). | ||
28 | + ContainsKey("code").ValueEqual("code", 0). | ||
29 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
30 | + ContainsKey("data").Value("data").Object(). | ||
31 | + ContainsKey("fileId").ValueNotEqual("fileId", BeZero()) | ||
32 | + }) | ||
33 | + }) | ||
34 | + }) | ||
35 | + AfterEach(func() { | ||
36 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
37 | + Expect(err).NotTo(HaveOccurred()) | ||
38 | + }) | ||
39 | +}) |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("编辑表格数据", func() { | ||
14 | + var fileId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&fileId), | ||
18 | + "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", | ||
19 | + "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("编辑表格数据", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "fileId": "int", | ||
28 | + } | ||
29 | + httpExpect.POST("/files/files/edit-data-table"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application" | ||
12 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
13 | + _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego" | ||
14 | +) | ||
15 | + | ||
16 | +func TestFile(t *testing.T) { | ||
17 | + RegisterFailHandler(Fail) | ||
18 | + RunSpecs(t, "Beego Port File Correlations Test Case Suite") | ||
19 | +} | ||
20 | + | ||
21 | +var handler http.Handler | ||
22 | +var server *httptest.Server | ||
23 | + | ||
24 | +var _ = BeforeSuite(func() { | ||
25 | + handler = web.BeeApp.Handlers | ||
26 | + server = httptest.NewServer(handler) | ||
27 | +}) | ||
28 | + | ||
29 | +var _ = AfterSuite(func() { | ||
30 | + server.Close() | ||
31 | +}) |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("持久化表格数据", func() { | ||
14 | + var fileId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&fileId), | ||
18 | + "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", | ||
19 | + "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("持久化表格数据", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "fileId": "int", | ||
28 | + } | ||
29 | + httpExpect.POST("/files/files/flush-data-table"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("生成主表", func() { | ||
14 | + var fileId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&fileId), | ||
18 | + "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", | ||
19 | + "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("生成主表", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "fileId": "int", | ||
28 | + } | ||
29 | + httpExpect.POST("/files/files/generate-main-table"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
test/integration/beego/file/get_file_test.go
0 → 100644
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回文件服务", func() { | ||
14 | + var fileId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&fileId), | ||
18 | + "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", | ||
19 | + "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据fileId参数返回文件", func() { | ||
23 | + Context("传入有效的fileId", func() { | ||
24 | + It("返回文件数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/files/{fileId}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回文件服务列表", func() { | ||
14 | + var fileId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&fileId), | ||
18 | + "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", | ||
19 | + "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数返回文件列表", func() { | ||
23 | + Context("传入有效的参数", func() { | ||
24 | + It("返回文件数据列表", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/files/"). | ||
27 | + WithQuery("offset", "int"). | ||
28 | + WithQuery("limit", "int"). | ||
29 | + Expect(). | ||
30 | + Status(http.StatusOK). | ||
31 | + JSON(). | ||
32 | + Object(). | ||
33 | + ContainsKey("code").ValueEqual("code", 0). | ||
34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
35 | + ContainsKey("data").Value("data").Object(). | ||
36 | + ContainsKey("count").ValueEqual("count", 1). | ||
37 | + ContainsKey("files").Value("files").Array() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("加载表格数据", func() { | ||
14 | + var fileId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&fileId), | ||
18 | + "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", | ||
19 | + "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("加载表格数据", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "fileId": "int", | ||
28 | + } | ||
29 | + httpExpect.POST("/files/files/load-data-table"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("移除文件服务", func() { | ||
14 | + var fileId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&fileId), | ||
18 | + "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", | ||
19 | + "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数移除文件服务", func() { | ||
23 | + Context("传入有效的fileId", func() { | ||
24 | + It("返回被移除文件的数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.DELETE("/files/{fileId}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package file | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新文件服务", func() { | ||
14 | + var fileId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&fileId), | ||
18 | + "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", | ||
19 | + "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("提交数据更新文件服务", func() { | ||
23 | + Context("提交正确的文件数据", func() { | ||
24 | + It("返回更新后的文件数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{} | ||
27 | + httpExpect.PUT("/files/{fileId}"). | ||
28 | + WithJSON(body). | ||
29 | + Expect(). | ||
30 | + Status(http.StatusOK). | ||
31 | + JSON(). | ||
32 | + Object(). | ||
33 | + ContainsKey("code").ValueEqual("code", 0). | ||
34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
35 | + ContainsKey("data").Value("data").Object(). | ||
36 | + ContainsKey("fileId").ValueEqual("fileId", fileId) | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + _, err := pG.DB.Exec("DELETE FROM files WHERE true") | ||
42 | + Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
-
请 注册 或 登录 后发表评论