Compare commits

...

242 Commits

Author SHA1 Message Date
c07c4d7217 version updates 2020-01-16 21:26:34 +08:00
b867b2a0bc add return parameter name for function Cas of gtype;improve Response.Redirect* functions by adding optional parameter code 2020-01-16 21:04:28 +08:00
872d674182 fix issue in database 'time' type support in package gdb 2020-01-15 21:23:40 +08:00
4682abafdf fix concurrent issue in gdb.Model.Count 2020-01-15 10:38:02 +08:00
b7d194cf52 improva gcmd.Parser/gres 2020-01-15 09:36:58 +08:00
edf2366296 improve gzip feature for gcompress; add gzip compression for package gres 2020-01-15 00:15:56 +08:00
22af5be71f rename parameter name for gipv4.Ip2Long/Long2Ip 2020-01-13 14:50:06 +08:00
f662ff8051 add pprof unit testing case for ghttp; reame updates 2020-01-12 22:26:07 +08:00
8c51121b3b version updates 2020-01-11 10:40:13 +08:00
e9a0805801 add function Schema for gdb 2020-01-10 23:48:19 +08:00
afadbc6621 improve genv.Remove/gproc.Kill 2020-01-10 22:32:07 +08:00
ca546fc30b why the goland auto removed my genv import? 2020-01-10 09:39:54 +08:00
7c7c168c3d improve gproc.SearchBinary 2020-01-09 23:05:03 +08:00
16f0bb96db improve strict parsing feature for gcmd 2020-01-08 23:06:01 +08:00
33a899d32e add As function for gdb.Model; improve string quote handling for gdb 2020-01-08 21:24:33 +08:00
f3a208f02f fix issue in router value retrieving for ghttp.Request 2020-01-08 20:00:42 +08:00
81fd3d06bb make parser default unstrict for gcmd 2020-01-08 19:30:56 +08:00
9227139cf8 add schema changing feature for gdb 2020-01-07 22:14:32 +08:00
f2190e50b2 improve unit testing for gdb 2020-01-06 20:43:59 +08:00
c4537b4753 improve ghttp.Client.Get 2020-01-06 17:57:07 +08:00
167d58490b Merge pull request #455 from gnever/191229_gfile_add_readline_mst
Add ReadLines and ReadByteLines read file content line by line
2020-01-06 17:52:41 +08:00
d36aceb9f1 Merge pull request #463 from sth4me/patch-1
fix mysql debug time
2020-01-06 17:51:33 +08:00
eb31922124 fix mysql debug time
调试模式时间格式改为毫秒,原来是微秒.
2020-01-06 10:28:34 +08:00
bec9f5a847 add buildin function 'concat' for gview 2020-01-05 19:55:17 +08:00
506552c3a9 example codes update; donator updates 2020-01-04 17:19:50 +08:00
2bacc77224 improve JSON/XML parsing feature for ghttp.Request 2020-01-04 15:35:21 +08:00
bc53f265af improve gconv.Map/String 2020-01-03 20:23:10 +08:00
344f232c36 add Timestamp*Str functions for gtime; improve unit testing cases for gfile 2020-01-02 21:29:06 +08:00
27b677b0c0 improve Map converting feature for gconv; improve package gproc for local shell searching; improve JSON/XML response for ghttp.Response 2020-01-02 19:45:41 +08:00
a5a0e381bd add more examples for ghttp.Server 2020-01-01 16:45:43 +08:00
d528d7f5ab donator updates 2020-01-01 15:24:10 +08:00
821c71bd8d improve parameter parsing feature for ghttp.Request 2020-01-01 15:20:03 +08:00
604a10400d improve parameter parsing feature for ghttp.Request 2020-01-01 14:57:57 +08:00
9219471f67 improve parameter parsing feature for ghttp.Request 2020-01-01 14:26:00 +08:00
fe5d2e5685 improve parameter parsing feature for ghttp.Request 2020-01-01 14:18:00 +08:00
0a89daa513 add more unit testing cases for gdb.TX 2019-12-31 16:02:18 +08:00
d6e6ddf996 Add gfile.ReadLines and gfile.ReadByteLines read file content line by line 2019-12-29 19:24:56 +08:00
5dbda8aedc fix issue in unit testing codes in gfile 2019-12-29 14:15:17 +08:00
134e4cf28f improve gfile.CopyDir function; add Model function for gdb.Model 2019-12-28 13:55:05 +08:00
56a85abef7 add AutoEncode feature for gview 2019-12-26 11:03:59 +08:00
80c6ceaf26 fix issue 437 2019-12-25 21:22:06 +08:00
a10f428715 add Iterator* functions for garray; add ReplaceDir*/ReplaceFile* functions for gfile; remove gfile.Replace/ReplaceFunc functions 2019-12-25 20:56:39 +08:00
597f7468e9 fix issue in prefix feature for method operations of gdb 2019-12-23 23:14:54 +08:00
5db8851213 comment update for gtype 2019-12-20 23:23:50 +08:00
1d53d760d8 README/DONATOR update; improve ghttp 2019-12-19 15:38:34 +08:00
922e720d63 improve gdb/ghttp/gins; fix issue in gstr 2019-12-19 15:14:05 +08:00
50018773b7 add iterate example for glist; improve variable name for ghttp.Server 2019-12-18 19:45:46 +08:00
df99036d41 add iterate example for glist; improve variable name for ghttp.Server 2019-12-18 19:44:40 +08:00
ae0fa888f0 add iterate example for glist; improve variable name for ghttp.Server 2019-12-18 19:40:07 +08:00
18892fb66d add iterate example for glist; improve variable name for ghttp.Server 2019-12-18 19:37:07 +08:00
5f2be10563 improve gdb/gtime 2019-12-17 21:06:34 +08:00
a5a88222a6 gofmt 2019-12-16 22:51:17 +08:00
4facdd5c9e gofmt 2019-12-16 21:22:42 +08:00
76bc9bd385 improve gdb.Model 2019-12-16 21:00:16 +08:00
364452f3bb improve gdb.Model 2019-12-16 20:50:27 +08:00
4996755f11 improve gcmd.Scan* 2019-12-14 22:48:53 +08:00
e33230a88f add package gbuild 2019-12-14 17:01:27 +08:00
951ce46932 fix data race issue in unit testing cases for gtcp 2019-12-13 18:50:54 +08:00
795c7395e6 fix data race issue in unit testing cases for gtcp 2019-12-13 17:40:29 +08:00
27cf47bcd3 improve table prefix and quote feature for gdb 2019-12-13 15:25:49 +08:00
58a25c6f61 fix data race issue in unit testing of gtcp 2019-12-13 14:26:07 +08:00
2d754f80b1 fix data race issue in unit testing of gtcp 2019-12-13 13:43:28 +08:00
f4e8fbe767 fix issue in unit testing codes for gtcp 2019-12-13 08:57:39 +08:00
458318d374 improve prefix and word quote feature for gdb; merge develop 2019-12-12 23:54:07 +08:00
e3f54e1353 improve tag and field retrieving feature for internal/structs; comment update for gdb 2019-12-12 23:38:46 +08:00
4374996073 add some Must* functions for gparser/gjson/gmd5/gsha1/gbase64 2019-12-12 11:40:23 +08:00
87295ef1fe improve process communication feature for gproc; add more slice converting functions for gconv 2019-12-11 21:22:41 +08:00
81d4082b6a fix issue in Retry.Interval type changed for gtcp 2019-12-11 14:54:38 +08:00
d7e19bc3f3 improve package feature for gtcp 2019-12-11 14:50:25 +08:00
34ef0ea792 add prefix feature for gdb 2019-12-10 21:14:15 +08:00
2804834540 rename GetRouterMap to GetRouterArray for ghttp.Server 2019-12-10 12:28:55 +08:00
add7dd5a45 merge develop 2019-12-09 23:22:49 +08:00
e40894ca45 add IsServiceHandler for ghttp.RouterItem 2019-12-09 23:19:39 +08:00
28825f5395 add gdebug.BuildInfo function; improving gproc 2019-12-09 21:53:44 +08:00
6ca5141020 some improving 2019-12-08 22:55:32 +08:00
fe4f8e1810 version updates 2019-12-05 19:46:50 +08:00
671157cb70 release updates 2019-12-05 12:34:33 +08:00
f775479c3f fix issue in ghttp.Request.GetRequest* 2019-12-05 10:44:31 +08:00
64bb72842e comment update for unit testing case of gdb 2019-12-04 22:38:58 +08:00
e1d4ba9d23 add GetError function for ghttp.Request 2019-12-04 19:50:49 +08:00
a1edd83add README/DONATOR update 2019-12-04 18:48:13 +08:00
f7d6883405 fix issue in gredis for int set/get 2019-12-04 18:43:16 +08:00
8448a70646 change minimum go version from 1.10. to 1.11; travis ci updates 2019-12-04 17:50:03 +08:00
4018bfa899 travis updates 2019-12-04 17:36:31 +08:00
3cc9ce74e1 add IsEmpty function for gdb.Record/Result 2019-12-04 17:01:30 +08:00
eac60d845f go.mod updates 2019-12-04 16:27:19 +08:00
835c045c92 fix unit testing case for gdb 2019-12-04 16:21:35 +08:00
be15f85eae remove sql.ErrNoRows error for select functions for gdb; improve configuration feature for gdb/glog/gview 2019-12-04 16:04:52 +08:00
3e27ea0259 change duration parameter type from interface{} to time.Duration for gcache/gfcache 2019-12-04 14:42:09 +08:00
6abe660287 export router map api for ghttp.Server; comment update for ghttp.Server 2019-12-04 13:55:08 +08:00
a06ca31530 improve middleware feature for ghttp.Server 2019-12-04 10:03:03 +08:00
890865251b improve routerMap handling for ghttp.Request 2019-12-03 17:16:52 +08:00
6af90cafee rename ghttp.Domain.AddBindMiddleware to BindMiddlewareDefault for ghttp 2019-12-02 23:05:05 +08:00
2e2363bb41 change routergroup parameter name 'g' to 'group' for unit testing cases of ghttp 2019-12-02 23:00:48 +08:00
108ced2b0b improve route priority handling for ghttp.Server 2019-12-02 21:26:12 +08:00
fcba650348 add more unit testing case for gview 2019-12-02 20:27:21 +08:00
1b8a082942 change view configuration name from 'view' to 'viewer' in gins 2019-12-02 20:08:45 +08:00
40570cdb03 change logger configuration name from 'logging' to 'logger' in gins 2019-12-02 19:55:45 +08:00
10451864e6 improve parameter handling for ghttp.Requset 2019-12-01 21:41:29 +08:00
55e2646367 comment update for ghttp.Server 2019-12-01 21:05:46 +08:00
c88839edb1 comment update for ghttp.ServerConfig 2019-12-01 14:24:56 +08:00
2a2cfc289c improve ghttp.Client 2019-12-01 14:07:36 +08:00
8bbeb186c2 add Exit feature for ghttp.Response 2019-11-30 20:41:53 +08:00
be4bf39719 comment update for container 2019-11-30 18:33:51 +08:00
459c69839a comment update for container 2019-11-30 18:28:11 +08:00
a5407e57d9 comment update for ghttp.Client 2019-11-30 10:24:19 +08:00
5c749e7762 improve parameters handling for ghttp.Request 2019-11-30 09:42:07 +08:00
b3fafc64f8 improve parameter handling for ghttp.Request 2019-11-29 22:02:19 +08:00
c7b0763ab0 comment and unit testing case update for gdb 2019-11-28 23:51:05 +08:00
0cfdf60de5 change model default unsafe for gdb 2019-11-28 23:23:11 +08:00
096bff791d change model default safe for gdb 2019-11-28 23:21:27 +08:00
0cce858641 improve configuration feature for ghttp.Server/gview/glog 2019-11-28 23:19:37 +08:00
bb45d8d578 improve template cache feature for gview 2019-11-28 14:29:58 +08:00
7e43aa6b9d improve parameter parsing for ghtto.Request; add configuration feature for gview 2019-11-28 11:18:09 +08:00
4ee7c82bf1 fix issue in empty slice converting panic for gconv.Struct 2019-11-28 08:46:38 +08:00
85caa40a3d fix issue in empty slice converting panic for gconv.Struct 2019-11-27 23:38:33 +08:00
f4654bf446 fix comment issue in example codes for gmap 2019-11-27 23:19:07 +08:00
94ed0bf9c9 fix issue in ghttp.Request.GetView 2019-11-26 15:12:58 +08:00
22e3705d3e improve ghttp.GracefulServer; add more unit test case for ghttp.Server.Middleware 2019-11-26 14:56:05 +08:00
9b1cc6e9c7 add special handle for configuration of mssql for gdb 2019-11-22 19:45:42 +08:00
9429c8ff83 improve gd.Model.Clone 2019-11-21 22:21:57 +08:00
056c6d4688 remove Array type case from internal/empty.IsNil checks 2019-11-21 21:57:50 +08:00
382356bc8d improve gerror for stack information; fix issue in gconv.String for nil *time.Time type 2019-11-21 21:49:00 +08:00
1deb3510f0 improve gerror, ghttp for error stack logging; improve custom view feature for ghttp.Request 2019-11-20 18:45:09 +08:00
dd7ae1b07a unit test case updates for gdb 2019-11-20 13:36:31 +08:00
04a8755162 travis updates 2019-11-20 12:34:03 +08:00
682f99a763 travis updates 2019-11-20 12:29:34 +08:00
61282d6dab travis updates 2019-11-20 12:27:23 +08:00
ad540f7c25 update travis for adding mysql password; add custom view feature for ghttp.Response 2019-11-20 12:09:26 +08:00
a4f191c1c6 fix issue in gdb.Model for repeated condition statements; remove concurrent safety feature of gview; add default template file feature for gview 2019-11-19 21:50:17 +08:00
43531c2680 improve glog for debug configuration; add GetInt*/GetUint* functions for ghttp.Request 2019-11-19 17:26:06 +08:00
635f5d36fd improve log feature of ghttp.Server; remove trace for Notice/Warning functions for glog 2019-11-15 22:50:31 +08:00
1becc4932c add more functions for gtcp; remove default domain set for cookie feature of ghttp.Server 2019-11-14 15:41:28 +08:00
e36dd06f22 Merge pull request #342 from myvfpx/master 2019-11-08 23:45:48 +08:00
8f2c62d444 improve logging feature for ghttp.Server 2019-11-08 19:52:49 +08:00
21efde1a38 fix issue in session feature of ghttp.Server 2019-11-08 09:06:01 +08:00
d8b6466ed0 fix issue in ghttp.Server 2019-11-07 21:02:24 +08:00
d7b0228e9e add build-in function 'replace' for gview 2019-11-07 20:56:17 +08:00
9da1277b47 improve session of file storage for ghttp.Server 2019-11-07 20:42:13 +08:00
a3fd0c9a4a improve session of file storage for ghttp.Server 2019-11-07 20:36:33 +08:00
ad7375b44b improve configuration feature for ghttp.Server 2019-11-07 16:40:34 +08:00
05120b585d improve configuration feature for glog/ghttp.Server 2019-11-07 11:32:25 +08:00
9e32d74c8c improve ConfigFromMap function for ghttp.Server 2019-11-06 20:23:41 +08:00
0e62510c6f improve configuration feature, add instance feature for package glog; add package guuid for UUID feature 2019-11-06 20:22:20 +08:00
c492de4fa8 improve multipart form parsing for ghttp.Server 2019-11-06 15:37:29 +08:00
6308380541 update example for uploading files feature for ghttp.Server 2019-11-06 10:39:59 +08:00
2609db1aec improve file uploading feature for ghttp.Server 2019-11-05 19:47:35 +08:00
6c54e73dbd add example for memory storage og gsession 2019-11-05 17:33:06 +08:00
21abe62633 improve gfsnotify; add cache for tempalte file content 2019-11-04 22:42:49 +08:00
e30b2b0732 improve gsession/gmap/gtree 2019-11-04 21:26:16 +08:00
dcb74ee9df comment update 2019-11-01 20:36:09 +08:00
82bf21e831 improve gfsnotify 2019-11-01 15:31:26 +08:00
66355354fc improve gfsnotify/gview and container 2019-10-31 23:37:33 +08:00
4204125dce improve gipv4.IsIntranet 2019-10-31 15:13:34 +08:00
e6aa9d3a46 add EncodeFile/EncodeFileToString functions for gbase64 2019-10-31 14:42:01 +08:00
9416cd1274 add CopyMap function for gutil; improve ghttp.Request 2019-10-30 23:26:57 +08:00
8b5ab846b2 improve unit test case for gmutex 2019-10-30 23:01:24 +08:00
a15b93be90 comment update for package gtcp/gipv4/gipv6 2019-10-30 19:55:50 +08:00
38ee5f7d53 improve performance of gdebug 2019-10-30 15:12:19 +08:00
6f9bbbf416 add debug info for ghttp.Server 2019-10-29 20:15:13 +08:00
143bc3d8e3 travis updates 2019-10-29 20:02:28 +08:00
ea75b1a936 travis updates 2019-10-29 20:00:46 +08:00
0dde8c735e add debug info for ghttp.Server 2019-10-29 19:59:24 +08:00
1ab7f00b91 add FieldsEx function for gdb.Model 2019-10-29 19:45:21 +08:00
3ef42bfbf0 improve internal/intlog 2019-10-29 17:15:02 +08:00
05fec23457 improve internal/cmdenv 2019-10-29 17:13:29 +08:00
7225e49aa0 add package intlog for GF internal logging usage; improve redis storage feature for gsession 2019-10-29 16:45:42 +08:00
14e9deb254 add more unit test cases for gsession 2019-10-29 10:01:05 +08:00
f9569b387f add ConnectTimeout configuration for gredis 2019-10-29 09:49:29 +08:00
a0722ed51f add redis session support for gsession 2019-10-28 20:48:52 +08:00
e9ace9b17a update comment for grpool/glog 2019-10-28 17:16:50 +08:00
4791d10761 fix issue in hijack error for websocket of ghttp.Server 2019-10-28 17:01:08 +08:00
c686b1c080 improve datetime coverting for gdb 2019-10-28 16:42:30 +08:00
056d6ebbd9 improve interface design for gsession.Storage 2019-10-28 16:07:01 +08:00
baa2cb68de donator updates 2019-10-26 11:38:18 +08:00
e4909b318b Merge branch 'develop' of https://github.com/gogf/gf into develop 2019-10-26 11:03:17 +08:00
f1b7cb37c6 add configuration feature for glog 2019-10-26 10:58:07 +08:00
734728fa9c improve time handling for gdb 2019-10-25 19:54:02 +08:00
b373ace065 update comment for gqueue.Len 2019-10-25 17:32:03 +08:00
bc7b5c8626 fix issue in status checks for static file serving 2019-10-25 17:04:17 +08:00
f2b45622d6 add debug for domain group testing 2019-10-25 16:57:54 +08:00
77cb219057 enable route map printing for domain group testing 2019-10-25 16:44:54 +08:00
cf34d7bd56 fix issue in gconv.Interfaces; improve storage interface for gsession 2019-10-25 13:49:03 +08:00
5adc9be0d9 gofmt 2019-10-25 10:43:59 +08:00
58b2efc900 version update 2019-10-24 21:05:23 +08:00
28326606f5 fix issue in resource file handler for ghttp.Server 2019-10-24 20:22:37 +08:00
91c98bbb60 fix issue in group router feature for domain 2019-10-24 19:44:30 +08:00
63cd1128a7 Merge pull request #346 from danvinhe/feature-optimize_grand.Str 2019-10-23 22:51:58 +08:00
c0236d7dfa improve gstr.SplitAndTrim 2019-10-22 13:57:21 +08:00
d4051df5b6 improve gdb/gstr/gconv/garray 2019-10-21 19:13:25 +08:00
88045417ff fix issue in field type check for gdb 2019-10-17 20:57:49 +08:00
500efb5601 fix issue in template for ghttp.Server 2019-10-17 20:31:03 +08:00
97fe8235da fix issue in session expiring for file storage of gsession; add Pop/Pops functions for gset/gmap 2019-10-16 23:33:06 +08:00
e1164e935b improve configuration for gdb; add more unit test case for ghttp.Server 2019-10-15 21:20:38 +08:00
b26330aee1 rename cacheTime to cacheExpire and change its type from int to time.Duration for gdb.Model; fix issue in string support of function Data for gdb 2019-10-15 17:44:47 +08:00
2b083709b5 add gmap.ListMap/TreeMap support for gdb.Where 2019-10-14 23:27:48 +08:00
0ac45dc379 rename file name from link_map to list_map for package gmap 2019-10-14 22:43:31 +08:00
650916c22a version updates 2019-10-14 13:46:45 +08:00
2804183325 fix issue in content-type response for ghttp.Server 2019-10-14 13:46:16 +08:00
2dc2610621 improve gdb; README update 2019-10-13 23:05:48 +08:00
1736e71e6b add debug for unit test case of 2019-10-13 22:40:23 +08:00
69ee5375b9 improve Join/String functions for garray/gset/gmap; add AddIfNotExistFunc/AddIfNotExistFuncLock functions for gset 2019-10-13 22:31:28 +08:00
3ac0a66887 improve unit test cases for gspath 2019-10-13 21:42:04 +08:00
20e873a1fc version updates 2019-10-13 00:40:06 +08:00
142484d89c add support for like statement in map key for Where function, improve error format for gdb 2019-10-13 00:37:25 +08:00
76a9f4ca14 fix security issue in static file feature for ghttp.Server 2019-10-12 23:56:03 +08:00
c4e5679d5c fix issue in missing passing MaxIdle/MaxActive configuration to underlying redis pool for gredis; add extra output for unit test cases of ghttp.Server 2019-10-11 23:33:21 +08:00
b08d7c3c38 change Join function feature for garray 2019-10-11 23:17:29 +08:00
5092d8e6c5 improve status handling and add error logger for ghttp.Server; fix issue in defer error warpping for some packages 2019-10-11 22:54:25 +08:00
74d625ff97 add Get*Int32/Get*Int64/Get*Uint32/Get*Uint64 functions for ghttp.Request 2019-10-10 10:40:38 +08:00
f1119e28e8 add Get*Int32/Get*Int64/Get*Uint32/Get*Uint64 functions for ghttp.Request 2019-10-10 10:33:14 +08:00
3082c7f761 fix issue in StrLimit for gstr 2019-10-10 00:04:38 +08:00
5f36614dd7 remove UseNumber for json decoding in package gjson 2019-10-09 20:33:26 +08:00
1dcc7a4887 improve http status handling for middleware of ghttp.Server 2019-10-09 15:26:50 +08:00
41e9d35487 improve middleware feature for ghttp.Server; fix issue memory usage in big file downloading 2019-10-09 00:33:58 +08:00
977c8b7ee3 version updates 2019-10-01 17:54:29 +08:00
939e6244ee comment update for gtcp/gudp 2019-10-01 17:53:49 +08:00
e764b2393d change params order of Insert* functions for glist; improve gstr.IsNumber 2019-10-01 16:35:44 +08:00
6384e75ed9 improva container for json marshal/unmarshal interface 2019-10-01 16:03:18 +08:00
195cae6577 add new functions and mark deprecated for some functions for gdb 2019-10-01 11:29:02 +08:00
c8cf46a5a7 add Create function for gvar; add Uints/SliceUint function for gconv 2019-10-01 10:42:34 +08:00
eba97277b2 add more unit test cases for ghttp 2019-10-01 09:33:26 +08:00
4e19fbc5fb add separate put/delete functions for ghttp.Request 2019-10-01 09:06:35 +08:00
494b5bbae2 fix issue in unit test case for gvar 2019-09-30 17:30:24 +08:00
987ce709e5 add UnmarshalJSON for gtime; add ineterface MapStrAny support for gjson.New 2019-09-30 17:23:23 +08:00
35ad4d869f fix issue in cycle import for gtime 2019-09-30 15:51:15 +08:00
39d654e3f2 update comment for gtime 2019-09-30 15:26:32 +08:00
7fe9c641f4 add UnmarshalJSON func tion for gset 2019-09-30 14:37:05 +08:00
ee1414c010 add UnmarshalJSON func tion for gmap/gvar 2019-09-30 14:23:15 +08:00
8eb1b685a5 improve UnmarshalJSON function for garray 2019-09-29 22:16:36 +08:00
46768d6f91 add UnmarshalJSON function and corresponding unit test cases for package grray 2019-09-29 20:47:59 +08:00
bb6fed3dc2 add UnmarshalJSON function and corresponding unit test cases for package gtype 2019-09-29 20:12:59 +08:00
47e74d27bf add MarshalJSON function to implement the interface MarshalJSON for json.Marshal for gtype 2019-09-29 15:59:09 +08:00
b830f9b96d improve ghttp.Server.Request for parameter retrieving; add Option feature for gdb; update example for hook feature of ghttp.Server 2019-09-29 14:27:09 +08:00
c85162a8a0 improving gdb.Model/gmap 2019-09-26 20:01:48 +08:00
ef4e128af7 fix issue in cors 2019-09-26 15:54:13 +08:00
cce8ac5118 The 'letters' already contain numbers, so just grab characters randomly from this. 2019-09-26 11:00:59 +08:00
cb7c3a9fa4 fix issue in index folder feature for ghttp.Server 2019-09-25 10:56:44 +08:00
b0f859cc91 improve example codes 2019-09-24 23:41:18 +08:00
6d4da529ee add websocket unit test case for ghttp 2019-09-24 21:08:28 +08:00
419b58452f 修改身份证尾数验证规则,新增银行卡号验证规则 2019-09-24 10:38:20 +08:00
b1835ea4e8 添加身份证号尾数验证规则,添加银行卡号验证规则 2019-09-24 10:21:37 +08:00
562 changed files with 24049 additions and 17936 deletions

View File

@ -1,16 +0,0 @@
package main
import "fmt"
func main() {
array := []uint{1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6}
for i := 0; i < len(array)-1; i++ {
for j := i + 1; j < len(array); j++ {
if array[i] == array[j] {
array = append(array[:j], array[j+1:]...)
}
}
}
fmt.Println(array)
}

View File

@ -0,0 +1,46 @@
package main
import (
"fmt"
"github.com/gogf/gf/container/garray"
)
func main() {
// Create a int array, which is concurrent-unsafe in default.
a := garray.NewIntArray()
// Appending items.
for i := 0; i < 10; i++ {
a.Append(i)
}
// Get the length of the array.
fmt.Println(a.Len())
// Get the slice of the array.
fmt.Println(a.Slice())
// Get the item of specified index.
fmt.Println(a.Get(6))
// Insert after/before specified index.
a.InsertAfter(9, 11)
a.InsertBefore(10, 10)
fmt.Println(a.Slice())
a.Set(0, 100)
fmt.Println(a.Slice())
// Searching the item and returning the index.
fmt.Println(a.Search(5))
// Remove item of specified index.
a.Remove(0)
fmt.Println(a.Slice())
// Clearing the array.
fmt.Println(a.Slice())
a.Clear()
fmt.Println(a.Slice())
}

View File

@ -1,59 +0,0 @@
package main
import (
"fmt"
"github.com/gogf/gf/container/garray"
)
func main() {
// 创建普通的int类型数组并关闭默认的并发安全特性
a := garray.NewIntArray(true)
// 添加数据项
for i := 0; i < 10; i++ {
a.Append(i)
}
// 获取当前数组长度
fmt.Println(a.Len())
// 获取当前数据项列表
fmt.Println(a.Slice())
// 获取指定索引项
fmt.Println(a.Get(6))
// 在指定索引前插入数据项
a.InsertAfter(9, 11)
// 在指定索引后插入数据项
a.InsertBefore(10, 10)
fmt.Println(a.Slice())
// 修改指定索引的数据项
a.Set(0, 100)
fmt.Println(a.Slice())
// 搜索数据项,返回搜索到的索引位置
fmt.Println(a.Search(5))
// 删除指定索引的数据项
a.Remove(0)
fmt.Println(a.Slice())
// 并发安全,写锁操作
a.LockFunc(func(array []int) {
// 将末尾项改为100
array[len(array)-1] = 100
})
// 并发安全,读锁操作
a.RLockFunc(func(array []int) {
fmt.Println(array[len(array)-1])
})
// 清空数组
fmt.Println(a.Slice())
a.Clear()
fmt.Println(a.Slice())
}

View File

@ -1,17 +0,0 @@
package main
import (
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/frame/g"
)
func main() {
a := garray.NewIntArray()
a.Append(1, 2, 3)
v := a.Slice()
v[0] = 4
g.Dump(a.Slice())
g.Dump(v)
}

View File

@ -0,0 +1,22 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/garray"
)
func main() {
type Student struct {
Id int
Name string
Scores *garray.IntArray
}
s := Student{
Id: 1,
Name: "john",
Scores: garray.NewIntArrayFrom([]int{100, 99, 98}),
}
b, _ := json.Marshal(s)
fmt.Println(string(b))
}

View File

@ -0,0 +1,19 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/garray"
)
func main() {
b := []byte(`{"Id":1,"Name":"john","Scores":[100,99,98]}`)
type Student struct {
Id int
Name string
Scores *garray.IntArray
}
s := Student{}
json.Unmarshal(b, &s)
fmt.Println(s)
}

View File

@ -1,20 +1,23 @@
package main
import (
"fmt"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/frame/g"
)
func main() {
array := garray.NewSortedStringArray()
array.Add("1")
array.Add("2")
array.Add("3")
array.Add("4")
array.Add("5")
array.Add("6")
array.Add("7")
array.Add("8")
array := garray.NewSortedStrArray()
array.Add("9")
g.Dump(array.Slice())
array.Add("8")
array.Add("7")
array.Add("6")
array.Add("5")
array.Add("4")
array.Add("3")
array.Add("2")
array.Add("1")
fmt.Println(array.Slice())
// output:
// [1 2 3 4 5 6 7 8 9]
}

View File

@ -1,27 +0,0 @@
package main
import (
"fmt"
"strings"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/frame/g"
)
func main() {
array := garray.NewSortedStringArray()
array.Add("/api/ctl/show")
array.Add("/api/ctl/post")
array.Add("/api/obj/rest")
array.Add("/api/handler")
array.Add("/api/obj/delete")
array.Add("/api/obj/show")
array.Add("/api/obj/my-show")
array.Add("/api/*")
array.Add("/api/ctl/rest")
array.Add("/api/ctl/my-show")
g.Dump(array.Slice())
fmt.Println(strings.Compare("/api/ctl/post", "/api/*"))
fmt.Println(strings.Compare("/api/*", "/api/ctl/my-show"))
}

View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"github.com/gogf/gf/container/glist"
)
func main() {
l := glist.New()
// Push
l.PushBack(1)
l.PushBack(2)
e := l.PushFront(0)
// Insert
l.InsertBefore(e, -1)
l.InsertAfter(e, "a")
fmt.Println(l)
// Pop
fmt.Println(l.PopFront())
fmt.Println(l.PopBack())
fmt.Println(l)
}

View File

@ -0,0 +1,23 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/glist"
"github.com/gogf/gf/frame/g"
)
func main() {
type Student struct {
Id int
Name string
Scores *glist.List
}
s := Student{
Id: 1,
Name: "john",
Scores: glist.NewFrom(g.Slice{100, 99, 98}),
}
b, _ := json.Marshal(s)
fmt.Println(string(b))
}

View File

@ -0,0 +1,19 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/glist"
)
func main() {
b := []byte(`{"Id":1,"Name":"john","Scores":[100,99,98]}`)
type Student struct {
Id int
Name string
Scores *glist.List
}
s := Student{}
json.Unmarshal(b, &s)
fmt.Println(s)
}

View File

@ -9,7 +9,7 @@ import (
func main() {
// 创建一个默认的gmap对象
// 默认情况下该gmap对象不支持并发安全特性
// 初始化时可以给定true参数关闭并发安全特性,当做一个普通的map使用
// 初始化时可以给定true参数开启并发安全特性,用以并发安全场景
m := gmap.New()
// 设置键值对

View File

@ -1,24 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/gmap"
)
func main() {
//m := gmap.New()
//m.Set("k", "v")
//m.Set("1", "2")
//b, err := json.Marshal(m)
//fmt.Println(err)
//fmt.Println(string(b))
m := gmap.NewIntIntMap()
m.Set(1, 2)
m.Set(3, 4)
b, err := json.Marshal(m)
fmt.Println(err)
fmt.Println(string(b))
}

View File

@ -0,0 +1,19 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/container/gmap"
)
func main() {
m := gmap.New()
m.Sets(g.MapAnyAny{
"name": "john",
"score": 100,
})
b, _ := json.Marshal(m)
fmt.Println(string(b))
}

View File

@ -0,0 +1,14 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/gmap"
)
func main() {
m := gmap.Map{}
s := []byte(`{"name":"john","score":100}`)
json.Unmarshal(s, &m)
fmt.Println(m.Map())
}

View File

@ -0,0 +1,26 @@
package main
import (
"github.com/gogf/gf/container/gmap"
"github.com/gogf/gf/frame/g"
)
func main() {
m1 := gmap.New(true)
m1.Set("1", "1")
m2 := m1.Map()
m2["2"] = "2"
g.Dump(m1.Clone())
g.Dump(m2)
//output:
//{
// "1": "1"
//}
//
//{
// "1": "1",
// "2": "2"
//}
}

View File

@ -1,17 +0,0 @@
package main
import (
"github.com/gogf/gf/container/gmap"
"github.com/gogf/gf/frame/g"
)
func main() {
m := gmap.New()
m.Set("1", "1")
m1 := m.Map()
m1["2"] = "2"
g.Dump(m.Clone())
g.Dump(m1)
}

View File

@ -10,9 +10,9 @@ import (
func main() {
array := g.Slice{2, 3, 1, 5, 4, 6, 8, 7, 9}
hashMap := gmap.New(true)
linkMap := gmap.NewLinkMap(true)
treeMap := gmap.NewTreeMap(gutil.ComparatorInt, true)
hashMap := gmap.New()
linkMap := gmap.NewListMap()
treeMap := gmap.NewTreeMap(gutil.ComparatorInt)
for _, v := range array {
hashMap.Set(v, v)
}

View File

@ -1,39 +0,0 @@
package main
import (
"fmt"
"sync"
"time"
)
// 验证 map 的delete方法是否并发安全
func main() {
// 创建一个初始化的map
m := make(map[int]int)
for i := 0; i < 10000; i++ {
m[i] = i
}
fmt.Println("map size:", len(m))
wg := sync.WaitGroup{}
ev := make(chan struct{}, 0)
// 创建10个并发的goroutine使用ev控制并发开始事件更容易模拟data race
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
<-ev
fmt.Println("start")
for i := 0; i < 10000; i++ {
delete(m, i)
}
wg.Done()
}()
}
time.Sleep(time.Second)
close(ev)
wg.Wait()
}

View File

@ -0,0 +1,22 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/gset"
)
func main() {
type Student struct {
Id int
Name string
Scores *gset.IntSet
}
s := Student{
Id: 1,
Name: "john",
Scores: gset.NewIntSetFrom([]int{100, 99, 98}),
}
b, _ := json.Marshal(s)
fmt.Println(string(b))
}

View File

@ -0,0 +1,19 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/gset"
)
func main() {
b := []byte(`{"Id":1,"Name":"john","Scores":[100,99,98]}`)
type Student struct {
Id int
Name string
Scores *gset.IntSet
}
s := Student{}
json.Unmarshal(b, &s)
fmt.Println(s)
}

View File

@ -0,0 +1,22 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/gtype"
)
func main() {
type Student struct {
Id *gtype.Int
Name *gtype.String
Scores *gtype.Interface
}
s := Student{
Id: gtype.NewInt(1),
Name: gtype.NewString("john"),
Scores: gtype.NewInterface([]int{100, 99, 98}),
}
b, _ := json.Marshal(s)
fmt.Println(string(b))
}

View File

@ -0,0 +1,19 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/container/gtype"
)
func main() {
b := []byte(`{"Id":1,"Name":"john","Scores":[100,99,98]}`)
type Student struct {
Id *gtype.Int
Name *gtype.String
Scores *gtype.Interface
}
s := Student{}
json.Unmarshal(b, &s)
fmt.Println(s)
}

View File

@ -0,0 +1,22 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/frame/g"
)
func main() {
type Student struct {
Id *g.Var
Name *g.Var
Scores *g.Var
}
s := Student{
Id: g.NewVar(1),
Name: g.NewVar("john"),
Scores: g.NewVar([]int{100, 99, 98}),
}
b, _ := json.Marshal(s)
fmt.Println(string(b))
}

View File

@ -0,0 +1,19 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/frame/g"
)
func main() {
b := []byte(`{"Id":1,"Name":"john","Scores":[100,99,98]}`)
type Student struct {
Id *g.Var
Name *g.Var
Scores *g.Var
}
s := Student{}
json.Unmarshal(b, &s)
fmt.Println(s)
}

View File

@ -30,8 +30,4 @@ func main() {
s := new(Score)
v.Struct(s)
fmt.Println(s)
// 只读接口
r := v.ReadOnly()
fmt.Println(r.String())
}

View File

@ -519,7 +519,6 @@ func getQueriedSqls() {
fmt.Println("Sql :", v.Sql)
fmt.Println("Args :", v.Args)
fmt.Println("Error:", v.Error)
fmt.Println("Func :", v.Func)
}
}

View File

@ -1,5 +1,16 @@
# MySQL数据库配置
[database]
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
# debug = true
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local"
#[database]
# [[database.default]]
# type = "mysql"
# link = "root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local"
#

View File

@ -0,0 +1,37 @@
package main
import (
"github.com/gogf/gf/database/gdb"
"sync"
"time"
)
var db gdb.DB
func init() {
gdb.AddDefaultConfigNode(gdb.ConfigNode{
Host: "127.0.0.1",
Port: "3306",
User: "root",
Pass: "12345678",
Name: "test",
Type: "mysql",
Role: "master",
Charset: "utf8",
MaxOpenConnCount: 100,
})
db, _ = gdb.New()
}
func main() {
wg := sync.WaitGroup{}
for i := 0; i < 100000; i++ {
wg.Add(1)
go func() {
defer wg.Done()
time.Sleep(10 * time.Second)
db.Table("user").Where("id=1").All()
}()
}
wg.Wait()
}

View File

@ -1,533 +0,0 @@
package main
import (
"fmt"
"time"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
)
// 本文件用于gf框架的mysql数据库操作示例不作为单元测试使用
var db gdb.DB
// 初始化配置及创建数据库
func init() {
gdb.AddDefaultConfigNode(gdb.ConfigNode{
Host: "127.0.0.1",
Port: "3306",
User: "root",
Pass: "12345678",
Name: "test",
Type: "mysql",
Role: "master",
Charset: "utf8",
})
db, _ = gdb.New()
//gins.Config().SetPath("/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/frame")
//db = g.Database()
//gdb.SetConfig(gdb.ConfigNode {
// Host : "127.0.0.1",
// Port : 3306,
// User : "root",
// Pass : "123456",
// Name : "test",
// Type : "mysql",
//})
//db, _ = gdb.Instance()
//gdb.SetConfig(gdb.Config {
// "default" : gdb.ConfigGroup {
// gdb.ConfigNode {
// Host : "127.0.0.1",
// Port : "3306",
// User : "root",
// Pass : "123456",
// Name : "test",
// Type : "mysql",
// Role : "master",
// Weight : 100,
// },
// gdb.ConfigNode {
// Host : "127.0.0.2",
// Port : "3306",
// User : "root",
// Pass : "123456",
// Name : "test",
// Type : "mysql",
// Role : "master",
// Weight : 100,
// },
// gdb.ConfigNode {
// Host : "127.0.0.3",
// Port : "3306",
// User : "root",
// Pass : "123456",
// Name : "test",
// Type : "mysql",
// Role : "master",
// Weight : 100,
// },
// gdb.ConfigNode {
// Host : "127.0.0.4",
// Port : "3306",
// User : "root",
// Pass : "123456",
// Name : "test",
// Type : "mysql",
// Role : "master",
// Weight : 100,
// },
// },
//})
//db, _ = gdb.Instance()
}
// 创建测试数据库
func create() {
fmt.Println("create:")
_, err := db.Exec("CREATE DATABASE IF NOT EXISTS test")
if err != nil {
fmt.Println(err)
}
s := `
CREATE TABLE IF NOT EXISTS user (
uid INT(10) UNSIGNED AUTO_INCREMENT,
name VARCHAR(45),
PRIMARY KEY (uid)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
`
_, err = db.Exec(s)
if err != nil {
fmt.Println(err)
}
s = `
CREATE TABLE IF NOT EXISTS user_detail (
uid INT(10) UNSIGNED AUTO_INCREMENT,
site VARCHAR(255),
PRIMARY KEY (uid)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
`
_, err = db.Exec(s)
if err != nil {
fmt.Println(err)
}
fmt.Println()
}
// 数据写入
func insert() {
fmt.Println("insert:")
r, err := db.Insert("user", gdb.Map{
"name": "john",
})
if err == nil {
uid, err2 := r.LastInsertId()
if err2 == nil {
r, err = db.Insert("user_detail", gdb.Map{
"uid": uid,
"site": "http://johng.cn",
})
if err == nil {
fmt.Printf("uid: %d\n", uid)
} else {
fmt.Println(err)
}
} else {
fmt.Println(err2)
}
} else {
fmt.Println(err)
}
fmt.Println()
}
// 基本sql查询
func query() {
fmt.Println("query:")
list, err := db.GetAll("select * from user limit 2")
if err == nil {
fmt.Println(list)
} else {
fmt.Println(err)
}
fmt.Println()
}
// replace into
func replace() {
fmt.Println("replace:")
r, err := db.Save("user", gdb.Map{
"uid": 1,
"name": "john",
})
if err == nil {
fmt.Println(r.LastInsertId())
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 数据保存
func save() {
fmt.Println("save:")
r, err := db.Save("user", gdb.Map{
"uid": 1,
"name": "john",
})
if err == nil {
fmt.Println(r.LastInsertId())
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 批量写入
func batchInsert() {
fmt.Println("batchInsert:")
_, err := db.BatchInsert("user", gdb.List{
{"name": "john_1"},
{"name": "john_2"},
{"name": "john_3"},
{"name": "john_4"},
}, 10)
if err != nil {
fmt.Println(err)
}
fmt.Println()
}
// 数据更新
func update1() {
fmt.Println("update1:")
r, err := db.Update("user", gdb.Map{"name": "john1"}, "uid=?", 1)
if err == nil {
fmt.Println(r.LastInsertId())
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 数据更新
func update2() {
fmt.Println("update2:")
r, err := db.Update("user", gdb.Map{"name": "john6"}, "uid=?", 1)
if err == nil {
fmt.Println(r.LastInsertId())
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 数据更新
func update3() {
fmt.Println("update3:")
r, err := db.Update("user", "name=?", "uid=?", "john2", 1)
if err == nil {
fmt.Println(r.LastInsertId())
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 链式查询操作1
func linkopSelect1() {
fmt.Println("linkopSelect1:")
r, err := db.Table("user u").LeftJoin("user_detail ud", "u.uid=ud.uid").Fields("u.*, ud.site").Where("u.uid > ?", 1).Limit(0, 2).Select()
if err == nil {
fmt.Println(r)
} else {
fmt.Println(err)
}
fmt.Println()
}
// 链式查询操作2
func linkopSelect2() {
fmt.Println("linkopSelect2:")
r, err := db.Table("user u").LeftJoin("user_detail ud", "u.uid=ud.uid").Fields("u.*,ud.site").Where("u.uid=?", 1).One()
if err == nil {
fmt.Println(r)
} else {
fmt.Println(err)
}
fmt.Println()
}
// 链式查询操作3
func linkopSelect3() {
fmt.Println("linkopSelect3:")
r, err := db.Table("user u").LeftJoin("user_detail ud", "u.uid=ud.uid").Fields("ud.site").Where("u.uid=?", 1).Value()
if err == nil {
fmt.Println(r.String())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 链式查询数量1
func linkopCount1() {
fmt.Println("linkopCount1:")
r, err := db.Table("user u").Fields("uid").LeftJoin("user_detail ud", "u.uid=ud.uid").Where("u.uid=?", 1).Count()
if err == nil {
fmt.Println(r)
} else {
fmt.Println(err)
}
fmt.Println()
}
// 错误操作
func linkopUpdate1() {
fmt.Println("linkopUpdate1:")
r, err := db.Table("henghe_setting").Update()
if err == nil {
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 通过Map指针方式传参方式
func linkopUpdate2() {
fmt.Println("linkopUpdate2:")
r, err := db.Table("user").Data(gdb.Map{"name": "john2"}).Where("name=?", "john_1").Update()
if err == nil {
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 通过字符串方式传参
func linkopUpdate3() {
fmt.Println("linkopUpdate3:")
r, err := db.Table("user").Data("name='john3'").Where("name=?", "john2").Update()
if err == nil {
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// Where条件使用Map
func linkopUpdate4() {
fmt.Println("linkopUpdate4:")
r, err := db.Table("user").Data(gdb.Map{"name": "john11111"}).Where(g.Map{"uid": 1}).Update()
if err == nil {
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 链式批量写入
func linkopBatchInsert1() {
fmt.Println("linkopBatchInsert1:")
r, err := db.Table("user").Data(gdb.List{
{"name": "john_1"},
{"name": "john_2"},
{"name": "john_3"},
{"name": "john_4"},
}).Insert()
if err == nil {
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 链式批量写入,指定每批次写入的条数
func linkopBatchInsert2() {
fmt.Println("linkopBatchInsert2:")
r, err := db.Table("user").Data(gdb.List{
{"name": "john_1"},
{"name": "john_2"},
{"name": "john_3"},
{"name": "john_4"},
}).Batch(2).Insert()
if err == nil {
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 链式批量保存
func linkopBatchSave() {
fmt.Println("linkopBatchSave:")
r, err := db.Table("user").Data(gdb.List{
{"uid": 1, "name": "john_1"},
{"uid": 2, "name": "john_2"},
{"uid": 3, "name": "john_3"},
{"uid": 4, "name": "john_4"},
}).Save()
if err == nil {
fmt.Println(r.RowsAffected())
} else {
fmt.Println(err)
}
fmt.Println()
}
// 事务操作示例1
func transaction1() {
fmt.Println("transaction1:")
if tx, err := db.Begin(); err == nil {
r, err := tx.Save("user", gdb.Map{
"uid": 1,
"name": "john",
})
tx.Rollback()
fmt.Println(r, err)
}
fmt.Println()
}
// 事务操作示例2
func transaction2() {
fmt.Println("transaction2:")
if tx, err := db.Begin(); err == nil {
r, err := tx.Table("user").Data(gdb.Map{"uid": 1, "name": "john_1"}).Save()
tx.Commit()
fmt.Println(r, err)
}
fmt.Println()
}
// 主从io复用测试在mysql中使用 show full processlist 查看链接信息
func keepPing() {
fmt.Println("keepPing:")
for {
fmt.Println("ping...")
err := db.PingMaster()
if err != nil {
fmt.Println(err)
return
}
err = db.PingSlave()
if err != nil {
fmt.Println(err)
return
}
time.Sleep(1 * time.Second)
}
}
// like语句查询
func likeQuery() {
fmt.Println("likeQuery:")
if r, err := db.Table("user").Where("name like ?", "%john%").Select(); err == nil {
fmt.Println(r)
} else {
fmt.Println(err)
}
}
// mapToStruct
func mapToStruct() {
type User struct {
Uid int
Name string
}
fmt.Println("mapToStruct:")
if r, err := db.Table("user").Where("uid=?", 1).One(); err == nil {
u := User{}
if err := r.ToStruct(&u); err == nil {
fmt.Println(r)
fmt.Println(u)
} else {
fmt.Println(err)
}
} else {
fmt.Println(err)
}
}
// getQueriedSqls
func getQueriedSqls() {
for k, v := range db.GetQueriedSqls() {
fmt.Println(k, ":")
fmt.Println("Sql :", v.Sql)
fmt.Println("Args :", v.Args)
fmt.Println("Error:", v.Error)
fmt.Println("Func :", v.Func)
}
}
func main() {
//data := g.Map{
// "nickname" : "john",
//}
//db.SetDebug(true)
//r, err := db.Table("user").Where("id=1").Data(data).Update()
//fmt.Println(err)
//fmt.Println(r.RowsAffected())
//data2 := g.Map{
// "adsys1" : "ss",
//}
//db.SetDebug(true)
//r, err := db.Table("cd_adsys").Where("adsys0=1").Data(data2).Update()
//fmt.Println(err)
//fmt.Println(r.RowsAffected())
//return
//db.SetDebug(true)
//r, err := db.Table("test").Where("id=1").One()
//fmt.Println(r["datetime"])
//fmt.Println(r["datetime"].Time().Date())
//fmt.Println(err)
//create()
//create()
//insert()
//query()
//replace()
//save()
//batchInsert()
//update1()
//update2()
//update3()
linkopSelect1()
//linkopSelect2()
//linkopSelect3()
//linkopCount1()
//linkopUpdate1()
//linkopUpdate2()
//linkopUpdate3()
//linkopUpdate4()
//
//transaction1()
//transaction2()
//
//keepPing()
//likeQuery()
//mapToStruct()
//getQueriedSqls()
}

View File

@ -0,0 +1,24 @@
package main
import (
"github.com/gogf/gf/frame/g"
)
func main() {
// error!
r, err := g.DB().Table("user").Where(g.Map{
"or": g.Map{
"nickname": "jim",
"create_time > ": "2019-10-01",
},
"and": g.Map{
"nickname": "tom",
"create_time > ": "2019-10-01",
},
}).All()
if err != nil {
panic(err)
}
g.Dump(r)
}

View File

@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/glog"
@ -23,7 +21,7 @@ func main() {
if err != nil {
panic(err)
}
db.SetDebug(true)
//db.SetDebug(false)
glog.SetPath("/tmp")
@ -36,7 +34,4 @@ func main() {
db.Table("user").Data(g.Map{"name": "smith"}).Where("uid=?", 1).Save()
db.PrintQueriedSqls()
fmt.Println(db.GetLastSql())
}

View File

@ -6,6 +6,7 @@ import (
func main() {
db := g.DB()
// 执行3条SQL查询
for i := 1; i <= 3; i++ {
db.Table("user").Where("id=?", i).One()

View File

@ -2,22 +2,26 @@ package main
import (
"fmt"
"github.com/gogf/gf/database/gdb"
"time"
"github.com/gogf/gf/frame/g"
)
func main() {
db := g.DB()
// 开启调试模式以便于记录所有执行的SQL
//db := g.DB()
gdb.AddDefaultConfigNode(gdb.ConfigNode{
LinkInfo: "root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local",
Type: "mysql",
Charset: "utf8",
})
db, _ := gdb.New()
db.SetDebug(true)
r, e := db.Table("user").Data(g.Map{
"passport": "1",
"password": "1",
"nickname": "1",
"create_time": time.Now(),
}).Insert()
type User struct {
CreateTime time.Time `orm:"create_time"`
}
r, e := db.Table("user").Data(User{CreateTime: time.Now()}).Insert()
if e != nil {
panic(e)
}

View File

@ -8,9 +8,9 @@ import (
func main() {
db := g.DB()
db.SetMaxIdleConns(10)
db.SetMaxOpenConns(10)
db.SetConnMaxLifetime(10)
db.SetMaxIdleConnCount(10)
db.SetMaxOpenConnCount(10)
db.SetMaxConnLifetime(time.Minute)
// 开启调试模式以便于记录所有执行的SQL
db.SetDebug(true)

View File

@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/gogf/gf/frame/g"
)
@ -10,11 +8,10 @@ func main() {
db := g.DB()
db.SetDebug(true)
r, e := db.Table("test").Where("id IN (?)", []interface{}{1, 2}).All()
one, e := db.Table("order.order o").LeftJoin("user.user u", "o.uid=u.id").Where("u.id", 1).One()
if e != nil {
panic(e)
}
if r != nil {
fmt.Println(r.ToList())
}
g.Dump(one)
}

View File

@ -0,0 +1,34 @@
package main
import (
"github.com/gogf/gf/frame/g"
"time"
)
func test1() {
db := g.DB()
db.SetDebug(true)
time.Sleep(1 * time.Minute)
r, e := db.Table("test").Where("id", 10000).Count()
if e != nil {
panic(e)
}
g.Dump(r)
}
func test2() {
db := g.DB()
db.SetDebug(true)
dao := db.Table("test").Safe()
time.Sleep(1 * time.Minute)
r, e := dao.Where("id", 10000).Count()
if e != nil {
panic(e)
}
g.Dump(r)
}
func main() {
test1()
test2()
}

View File

@ -520,7 +520,6 @@ func getQueriedSqls() {
fmt.Println("Sql :", v.Sql)
fmt.Println("Args :", v.Args)
fmt.Println("Error:", v.Error)
fmt.Println("Func :", v.Func)
}
}

View File

@ -1,47 +1,47 @@
package main
//import (
// _ "github.com/mattn/go-sqlite3"
// "github.com/gogf/gf/database/gdb"
// "github.com/gogf/gf/frame/g"
// "fmt"
//)
//
//func main() {
// gdb.SetConfig(gdb.Config{
// "default": gdb.ConfigGroup{
// gdb.ConfigNode{
// Name: "/tmp/my.db",
// Type: "sqlite",
// },
// },
// })
// db := g.Database()
// if db == nil {
// panic("db create failed")
// }
// defer db.Close()
//
// // 创建表
// sql := `CREATE TABLE user (
// uid INT PRIMARY KEY NOT NULL,
// name VARCHAR(30) NOT NULL
// );`
// if _, err := db.Exec(sql); err != nil {
// fmt.Println(err)
// }
//
// // 写入数据
// result, err := db.Table("user").Data(g.Map{"uid" : 1, "name" : "john"}).Save()
// if err == nil {
// fmt.Println(result.RowsAffected())
// } else {
// fmt.Println(err)
// }
//
// // 删除表
// sql = `DROP TABLE user;`
// if _, err := db.Exec(sql); err != nil {
// fmt.Println(err)
// }
//}
import (
"fmt"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
_ "github.com/mattn/go-sqlite3"
)
func main() {
gdb.SetConfig(gdb.Config{
"default": gdb.ConfigGroup{
gdb.ConfigNode{
Name: "/tmp/my.db",
Type: "sqlite",
},
},
})
db := g.DB()
if db == nil {
panic("db create failed")
}
// 创建表
sql := `CREATE TABLE user (
uid INT PRIMARY KEY NOT NULL,
name VARCHAR(30) NOT NULL
);`
if _, err := db.Exec(sql); err != nil {
fmt.Println(err)
}
// 写入数据
result, err := db.Table("user").Data(g.Map{"uid": 1, "name": "john"}).Save()
if err == nil {
fmt.Println(result.RowsAffected())
} else {
fmt.Println(err)
}
// 删除表
sql = `DROP TABLE user;`
if _, err := db.Exec(sql); err != nil {
fmt.Println(err)
}
}

View File

@ -1,60 +0,0 @@
package main
import (
"fmt"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/os/gcmd"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/database/gredis"
"github.com/gogf/gf/frame/g"
)
func main() {
batchNumber := 1000
redis1Config, err := gredis.ConfigFromStr("im-redis-slave:6379,9")
if err != nil {
panic(err)
}
redis2Config, err := gredis.ConfigFromStr("r-bp1f0a5d4efd8744.redis.rds.aliyuncs.com:6379,9")
if err != nil {
panic(err)
}
gredis.SetConfig(redis1Config)
v, err := g.Redis().DoVar("keys", "*")
if err != nil {
panic(err)
}
array := garray.NewStrArrayFrom(v.Strings())
for {
slice := array.PopLefts(batchNumber)
if len(slice) > 0 {
// `migrate %s %d "" 0 2000 copy replace auth %s keys %s`,
params := g.Slice{
redis2Config.Host,
redis2Config.Port,
"",
redis2Config.Db,
2000,
"copy",
"replace",
"keys",
}
params = append(params, gconv.Interfaces(slice)...)
fmt.Println(params)
if gcmd.GetOpt("dryrun") == "0" {
if v, err := g.Redis().DoVar("migrate", params...); err != nil {
panic(err)
} else {
fmt.Println(v.String())
}
}
} else {
break
}
}
fmt.Println("done")
}

View File

@ -6,6 +6,7 @@ import (
)
func main() {
gdebug.PrintStack()
fmt.Println(gdebug.CallerPackage())
fmt.Println(gdebug.CallerFunction())
}

View File

@ -0,0 +1,10 @@
package main
import (
"fmt"
"github.com/gogf/gf/debug/gdebug"
)
func main() {
fmt.Println(gdebug.BuildInfo())
}

View File

@ -1,4 +1,4 @@
package main
package gbase64
import (
"fmt"

View File

@ -9,26 +9,19 @@ import (
func main() {
// 使用gbinary.Encoded对基本数据类型进行二进制打包
if buffer, err := gbinary.Encode(18, 300, 1.01); err != nil {
glog.Error(err)
} else {
fmt.Println(buffer)
}
fmt.Println(gbinary.Encode(18, 300, 1.01))
// 使用gbinary.Decode对整形二进制解包注意第二个及其后参数为字长确定的整形变量的指针地址字长确定的类型
// 例如int8/16/32/64、uint8/16/32/64、float32/64
// 这里的1.01默认为float64类型(64位系统下)
if buffer, err := gbinary.Encode(18, 300, 1.01); err != nil {
buffer := gbinary.Encode(18, 300, 1.01)
var i1 int8
var i2 int16
var f3 float64
if err := gbinary.Decode(buffer, &i1, &i2, &f3); err != nil {
glog.Error(err)
} else {
var i1 int8
var i2 int16
var f3 float64
if err := gbinary.Decode(buffer, &i1, &i2, &f3); err != nil {
glog.Error(err)
} else {
fmt.Println(i1, i2, f3)
}
fmt.Println(i1, i2, f3)
}
// 编码/解析 int自动识别变量长度

View File

@ -15,6 +15,6 @@ func main() {
}
redisCfg := new(RedisConfig)
fmt.Println(g.Config().GetToStruct("redis", redisCfg))
fmt.Println(g.Config().GetStruct("redis", redisCfg))
fmt.Println(redisCfg)
}

View File

@ -15,4 +15,6 @@ func main() {
panic(err)
}
fmt.Println(str)
// output:
// 花间一壶酒,独酌无相亲。
}

View File

@ -0,0 +1,19 @@
package main
import (
"fmt"
"github.com/gogf/gf/encoding/gjson"
)
func main() {
s := `
{"apiVersion":"v1","kind":"Service","metadata":{"labels":{"name":"http-daemon"},"name":"http-daemon","namespace":"default"},"spec":{"ports":[{"name":"http-daemon","port":8080,"protocol":"TCP","targetPort":9212}],"selector":{"app":"http-daemon","version":"v0930-082326"}}}
`
js, err := gjson.DecodeToJson(s)
if err != nil {
panic(err)
}
//g.Dump(js.ToMap())
y, _ := js.ToYamlString()
fmt.Println(y)
}

View File

@ -19,7 +19,7 @@ func getWithPattern1() {
}
}`
if p, e := gparser.LoadContent([]byte(data), "json"); e != nil {
if p, e := gparser.LoadContent([]byte(data)); e != nil {
glog.Error(e)
} else {
fmt.Println("John Score:", p.GetFloat32("users.list.1.score"))
@ -36,7 +36,7 @@ func getWithPattern2() {
<body>Don't forget me this weekend!</body>
</note>`
if p, e := gparser.LoadContent([]byte(data), "xml"); e != nil {
if p, e := gparser.LoadContent([]byte(data)); e != nil {
glog.Error(e)
} else {
fmt.Println("Heading:", p.GetString("note.heading"))
@ -52,7 +52,7 @@ func multiDots1() {
},
"users.count" : 101
}`
if p, e := gparser.LoadContent([]byte(data), "json"); e != nil {
if p, e := gparser.LoadContent([]byte(data)); e != nil {
glog.Error(e)
} else {
fmt.Println("Users Count:", p.Get("users.count"))
@ -70,7 +70,7 @@ func multiDots2() {
"count.type1" : 100
}
}`
if p, e := gparser.LoadContent([]byte(data), "json"); e != nil {
if p, e := gparser.LoadContent([]byte(data)); e != nil {
glog.Error(e)
} else {
fmt.Println("Users Count:", p.Get("users.count.type1"))
@ -88,7 +88,7 @@ func set1() {
<list><title>gf article2</title><content>gf content2</content></list>
<list><title>gf article3</title><content>gf content3</content></list>
</article>`
if p, e := gparser.LoadContent([]byte(data), "xml"); e != nil {
if p, e := gparser.LoadContent([]byte(data)); e != nil {
glog.Error(e)
} else {
p.Set("article.list.0", nil)
@ -105,7 +105,7 @@ func set2() {
"count" : 100
}
}`
if p, e := gparser.LoadContent([]byte(data), "json"); e != nil {
if p, e := gparser.LoadContent([]byte(data)); e != nil {
glog.Error(e)
} else {
p.Set("users.count", 1)
@ -116,7 +116,7 @@ func set2() {
}
func makeXml1() {
p := gparser.New()
p := gparser.New(nil)
p.Set("name", "john")
p.Set("age", 18)
p.Set("scores", map[string]int{
@ -133,7 +133,7 @@ func makeJson1() {
Id int `json:"id"`
Price float32 `json:"price"`
}
p := gparser.New()
p := gparser.New(nil)
p.Set("orders.list.0", Order{1, 100})
p.Set("orders.list.1", Order{2, 666})
p.Set("orders.list.2", Order{3, 999.99})

View File

@ -1,4 +0,0 @@
# MySQL数据库配置
[database]
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test"

View File

@ -1,13 +0,0 @@
package main
import (
"github.com/gogf/gf/.example/frame/mvc/model/test"
"github.com/gogf/gf/frame/g"
)
func main() {
g.DB().SetDebug(true)
user, err := test.ModelUser().One()
g.Dump(err)
g.Dump(user)
}

View File

@ -1,33 +0,0 @@
{
"viewpath" : "/home/www/templates/",
"database" : {
"default" : [
{
"host" : "127.0.0.1",
"port" : "3306",
"user" : "root",
"pass" : "123456",
"name" : "test",
"type" : "mysql",
"role" : "master",
"charset" : "utf8",
"priority" : "1"
},
{
"host" : "127.0.0.1",
"port" : "3306",
"user" : "root",
"pass" : "123456",
"name" : "test",
"type" : "mysql",
"role" : "master",
"charset" : "utf8",
"priority" : "1"
}
]
},
"redis" : {
"disk" : "127.0.0.1:6379,0",
"cache" : "127.0.0.1:6379,1"
}
}

View File

@ -1,4 +0,0 @@
viewpath = "/home/www/templates"
[redis]
disk = "127.0.0.1:6379,0"
cache = "127.0.0.1:6379,1"

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<!-- 模板引擎目录 -->
<viewpath>/home/www/templates/</viewpath>
<!-- MySQL数据库配置 -->
<database>
<default>
<host>127.0.0.1</host>
<port>3306</port>
<user>root</user>
<pass>123456</pass>
<name>test</name>
<role>master</role>
<type>mysql</type>
<charset>utf8</charset>
<priority>1</priority>
</default>
<default>
<host>127.0.0.1</host>
<port>3306</port>
<user>root</user>
<pass>123456</pass>
<name>test</name>
<role>master</role>
<type>mysql</type>
<charset>utf8</charset>
<priority>1</priority>
</default>
</database>
<!-- Redis数据库配置 -->
<redis>
<disk>127.0.0.1:6379,0</disk>
<cache>127.0.0.1:6379,1</cache>
</redis>
</config>

View File

@ -1,27 +0,0 @@
# 模板引擎目录
viewpath: /home/www/templates/
# MySQL数据库配置
database:
default:
- host: 127.0.0.1
port: 3306
user: root
pass: "8692651"
name: test
type: mysql
role: master
charset: utf8
priority: 1
- host: 127.0.0.1
port: 3306
user: root
pass: "8692651"
name: test
type: mysql
role: master
charset: utf8
priority: 1
# Redis数据库配置
redis:
default: 127.0.0.1:6379,0
cache : 127.0.0.1:6379,2

View File

@ -1,25 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
func init() {
s := g.Server()
s.BindHandler("/apple", Apple)
s.BindHandler("/pen", Pen)
s.BindHandler("/apple-pen", ApplePen)
}
func Apple(r *ghttp.Request) {
r.Response.Write("Apple")
}
func Pen(r *ghttp.Request) {
r.Response.Write("Pen")
}
func ApplePen(r *ghttp.Request) {
r.Response.Write("Apple-Pen")
}

View File

@ -1,16 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
type Order struct{}
func init() {
g.Server().BindObject("/{.struct}-{.method}", new(Order))
}
func (o *Order) List(r *ghttp.Request) {
r.Response.Write("List")
}

View File

@ -1,12 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/gins"
"github.com/gogf/gf/net/ghttp"
)
func init() {
ghttp.GetServer().BindHandler("/config", func(r *ghttp.Request) {
r.Response.Write(gins.Config().GetString("database.default.0.host"))
})
}

View File

@ -1,16 +0,0 @@
package demo
import (
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gtime"
)
func init() {
ghttp.GetServer().BindHandler("/cookie", Cookie)
}
func Cookie(r *ghttp.Request) {
datetime := r.Cookie.Get("datetime")
r.Cookie.Set("datetime", gtime.Datetime())
r.Response.Write("datetime:" + datetime)
}

View File

@ -1,20 +0,0 @@
package demo
import (
"github.com/gogf/gf/net/ghttp"
)
type ControllerDomain struct{}
// 初始化控制器对象并绑定操作到Web Server
func init() {
// 只有localhost域名下才能访问该对象
// 对应URL为http://localhost:8199/test/show
// 通过该地址将无法访问到内容http://127.0.0.1:8199/test/show
ghttp.GetServer().Domain("localhost").BindObject("/domain", &ControllerDomain{})
}
// 用于对象映射
func (d *ControllerDomain) Show(r *ghttp.Request) {
r.Response.Write("It's show time bibi!")
}

View File

@ -1,24 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/gmvc"
"github.com/gogf/gf/net/ghttp"
)
type ControllerExit struct {
gmvc.Controller
}
func (c *ControllerExit) Init(r *ghttp.Request) {
c.Controller.Init(r)
c.Response.Write("exit, it will not print \"show\"")
c.Request.Exit()
}
func (c *ControllerExit) Show() {
c.Response.Write("show")
}
func init() {
ghttp.GetServer().BindController("/exit", &ControllerExit{})
}

View File

@ -1,36 +0,0 @@
package demo
import (
"fmt"
"github.com/gogf/gf/net/ghttp"
)
func Form(r *ghttp.Request) {
fmt.Println(r.GetPostMap())
fmt.Println(r.GetPostString("name"))
fmt.Println(r.GetPostString("age"))
}
func FormShow(r *ghttp.Request) {
r.Response.Write(`
<html>
<head>
<title>表单提交</title>
</head>
<body>
<form enctype="application/x-www-form-urlencoded" action="/form" method="post">
<input type="input" name="name" />
<input type="input" name="age" />
<input type="submit" value="submit" />
</form>
</body>
</html>
`)
}
func init() {
ghttp.GetServer().BindHandler("/form", Form)
ghttp.GetServer().BindHandler("/form/show", FormShow)
}

View File

@ -1,9 +0,0 @@
package demo
import "github.com/gogf/gf/net/ghttp"
func init() {
ghttp.GetServer().BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("Hello World!")
})
}

View File

@ -1,30 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
)
type Method struct {
gmvc.Controller
}
func init() {
// 第三个参数指定主要注册的方法,其他方法不注册,方法名称会自动追加到给定路由后面,构成新路由
// 以下注册会中注册两个新路由: /method/name, /method/age
g.Server().BindController("/method", new(Method), "Name, Age")
// 绑定路由到指定的方法执行,以下注册只会注册一个路由: /method-name
g.Server().BindControllerMethod("/method-name", new(Method), "Name")
}
func (c *Method) Name() {
c.Response.Write("John")
}
func (c *Method) Age() {
c.Response.Write("18")
}
func (c *Method) Info() {
c.Response.Write("Info")
}

View File

@ -1,20 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
type Object struct{}
func init() {
g.Server().BindObject("/object", new(Object))
}
func (o *Object) Index(r *ghttp.Request) {
r.Response.Write("object index")
}
func (o *Object) Show(r *ghttp.Request) {
r.Response.Write("object show")
}

View File

@ -1,31 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
type ObjectMethod struct{}
func init() {
obj := &ObjectMethod{}
g.Server().BindObject("/object-method", obj, "Show1, Show2, Show3")
g.Server().BindObjectMethod("/object-method-show1", obj, "Show1")
g.Server().Domain("localhost").BindObject("/object-method", obj, "Show4")
}
func (o *ObjectMethod) Show1(r *ghttp.Request) {
r.Response.Write("show 1")
}
func (o *ObjectMethod) Show2(r *ghttp.Request) {
r.Response.Write("show 2")
}
func (o *ObjectMethod) Show3(r *ghttp.Request) {
r.Response.Write("show 3")
}
func (o *ObjectMethod) Show4(r *ghttp.Request) {
r.Response.Write("show 4")
}

View File

@ -1,30 +0,0 @@
package demo
import "github.com/gogf/gf/net/ghttp"
// 测试绑定对象
type ObjectRest struct{}
func init() {
ghttp.GetServer().BindObjectRest("/object-rest", &ObjectRest{})
}
// RESTFul - GET
func (o *ObjectRest) Get(r *ghttp.Request) {
r.Response.Write("RESTFul HTTP Method GET")
}
// RESTFul - POST
func (c *ObjectRest) Post(r *ghttp.Request) {
r.Response.Write("RESTFul HTTP Method POST")
}
// RESTFul - DELETE
func (c *ObjectRest) Delete(r *ghttp.Request) {
r.Response.Write("RESTFul HTTP Method DELETE")
}
// 该方法无法映射,将会无法访问到
func (c *ObjectRest) Hello(r *ghttp.Request) {
r.Response.Write("Hello")
}

View File

@ -1,25 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
type Product struct {
total int
}
func init() {
p := &Product{}
g.Server().BindHandler("/product/total", p.Total)
g.Server().BindHandler("/product/list/{page}.html", p.List)
}
func (p *Product) Total(r *ghttp.Request) {
p.total++
r.Response.Write("total: ", p.total)
}
func (p *Product) List(r *ghttp.Request) {
r.Response.Write("page: ", r.Get("page"))
}

View File

@ -1,34 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
)
type Rest struct {
gmvc.Controller
}
func init() {
g.Server().BindControllerRest("/rest", &Rest{})
}
// RESTFul - GET
func (c *Rest) Get() {
c.Response.Write("RESTFul HTTP Method GET")
}
// RESTFul - POST
func (c *Rest) Post() {
c.Response.Write("RESTFul HTTP Method POST")
}
// RESTFul - DELETE
func (c *Rest) Delete() {
c.Response.Write("RESTFul HTTP Method DELETE")
}
// 该方法无法映射,将会无法访问到
func (c *Rest) Hello() {
c.Response.Write("Hello")
}

View File

@ -1,18 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
)
type ControllerRule struct {
gmvc.Controller
}
func init() {
g.Server().BindController("/rule/{method}/:name", &ControllerRule{})
}
func (c *ControllerRule) Show() {
c.Response.Write(c.Request.Get("name"))
}

View File

@ -1,17 +0,0 @@
package demo
import (
"strconv"
"github.com/gogf/gf/net/ghttp"
)
func init() {
ghttp.GetServer().BindHandler("/session", Session)
}
func Session(r *ghttp.Request) {
id := r.Session.GetInt("id")
r.Session.Set("id", id+1)
r.Response.Write("id:" + strconv.Itoa(id))
}

View File

@ -1,23 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/gmvc"
"github.com/gogf/gf/net/ghttp"
)
type ControllerTemplate struct {
gmvc.Controller
}
func (c *ControllerTemplate) Info() {
c.View.Assign("name", "john")
c.View.Assigns(map[string]interface{}{
"age": 18,
"score": 100,
})
c.View.Display("view/user/index.tpl")
}
func init() {
ghttp.GetServer().BindController("/template", &ControllerTemplate{})
}

View File

@ -1,16 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
func init() {
ghttp.GetServer().BindHandler("/template2", func(r *ghttp.Request) {
content, _ := g.View().Parse("index.tpl", map[string]interface{}{
"id": 123,
"name": "john",
})
r.Response.Write(content)
})
}

View File

@ -1,17 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/gins"
"github.com/gogf/gf/net/ghttp"
)
func init() {
gins.View().SetPath("/home/www/template/")
ghttp.GetServer().BindHandler("/template3", func(r *ghttp.Request) {
content, _ := gins.View().Parse("index.tpl", map[string]interface{}{
"id": 123,
"name": "john",
})
r.Response.Write(content)
})
}

View File

@ -1,40 +0,0 @@
package demo
import (
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gfile"
)
func Upload(r *ghttp.Request) {
if f, h, e := r.FormFile("upload-file"); e == nil {
defer f.Close()
fname := gfile.Basename(h.Filename)
buffer := make([]byte, h.Size)
f.Read(buffer)
gfile.PutBytes("/tmp/"+fname, buffer)
r.Response.Write(fname + " uploaded successly")
} else {
r.Response.Write(e.Error())
}
}
func UploadShow(r *ghttp.Request) {
r.Response.Write(`
<html>
<head>
<title>上传文件</title>
</head>
<body>
<form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="upload-file" />
<input type="submit" value="upload" />
</form>
</body>
</html>
`)
}
func init() {
ghttp.GetServer().BindHandler("/upload", Upload)
ghttp.GetServer().BindHandler("/upload/show", UploadShow)
}

View File

@ -1,29 +0,0 @@
package demo
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
)
type User struct {
gmvc.Controller
}
func init() {
s := g.Server()
s.BindController("/user", new(User))
s.BindController("/user/{.method}/{uid}", new(User), "Info")
s.BindController("/user/{.method}/{page}.html", new(User), "List")
}
func (u *User) Index() {
u.Response.Write("User")
}
func (u *User) Info() {
u.Response.Write("Info - Uid: ", u.Request.Get("uid"))
}
func (u *User) List() {
u.Response.Write("List - Page: ", u.Request.Get("page"))
}

View File

@ -1,19 +0,0 @@
package stats
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
var (
total int
)
func init() {
g.Server().BindHandler("/stats/total", showTotal)
}
func showTotal(r *ghttp.Request) {
total++
r.Response.Write("total:", total)
}

View File

@ -1,15 +0,0 @@
package main
import (
_ "github.com/gogf/gf/.example/frame/mvc/controller/demo"
_ "github.com/gogf/gf/.example/frame/mvc/controller/stats"
"github.com/gogf/gf/frame/g"
)
func main() {
//g.Server().SetDumpRouteMap(false)
g.Server().SetPort(8199)
g.Server().Run()
}

View File

@ -1,8 +0,0 @@
package test
import "github.com/gogf/gf/database/gdb"
var (
// ConfigGroup is the configuration group name for this model.
ConfigGroup = gdb.DEFAULT_GROUP_NAME
)

View File

@ -1,92 +0,0 @@
package test
import (
"database/sql"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/os/gtime"
)
// User is the golang structure for table user.
type User struct {
Id int `orm:"id,primary" json:"id"`
Passport string `orm:"passport" json:"passport"`
Password string `orm:"password" json:"password"`
NickName string `orm:"nickname" json:"nick_name"`
CreateTime *gtime.Time `orm:"create_time" json:"create_time"`
}
// UserModel is the model of convenient operations for table user.
type UserModel struct {
*gdb.Model
TableName string
}
var (
// UserTableName is the table name of user.
UserTableName = "user"
)
// ModelUser creates and returns a new model object for table user.
func ModelUser() *UserModel {
return &UserModel{
g.DB(ConfigGroup).Table(UserTableName).Safe(),
UserTableName,
}
}
// Inserts does "INSERT...INTO..." statement for inserting current object into table.
func (r *User) Insert() (result sql.Result, err error) {
return ModelUser().Data(r).Insert()
}
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
// If there's already another same record in the table (it checks using primary key or unique index),
// it deletes it and insert this one.
func (r *User) Replace() (result sql.Result, err error) {
return ModelUser().Data(r).Replace()
}
// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
// It updates the record if there's already another same record in the table
// (it checks using primary key or unique index).
func (r *User) Save() (result sql.Result, err error) {
return ModelUser().Data(r).Save()
}
// Update does "UPDATE...WHERE..." statement for updating current object from table.
// It updates the record if there's already another same record in the table
// (it checks using primary key or unique index).
func (r *User) Update() (result sql.Result, err error) {
return ModelUser().Data(r).Where(gdb.GetWhereConditionOfStruct(r)).Update()
}
// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
func (r *User) Delete() (result sql.Result, err error) {
return ModelUser().Where(gdb.GetWhereConditionOfStruct(r)).Delete()
}
// Select overwrite the Select method from gdb.Model for model
// as retuning all objects with specified structure.
func (m *UserModel) Select() ([]*User, error) {
array := ([]*User)(nil)
if err := m.Scan(&array); err != nil {
return nil, err
}
return array, nil
}
// First does the same logistics as One method from gdb.Model for model
// as retuning first/one object with specified structure.
func (m *UserModel) First() (*User, error) {
list, err := m.Select()
if err != nil {
return nil, err
}
if len(list) > 0 {
return list[0], nil
}
return nil, nil
}

View File

@ -1,11 +0,0 @@
<html>
<head>
<title>上传文件</title>
</head>
<body>
<form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="upload-file" />
<input type="submit" value="upload" />
</form>
</body>
</html>

View File

@ -1,2 +0,0 @@
<h3>This is footer</h3>
<div style="color:red">tpl vals: {{.}}</div>

View File

@ -1,11 +0,0 @@
<html>
<head>
<title></title>
</head>
<body>
<h3>This is index</h3>
<p>tpl vals: {{.}}</p>
{{include "user/footer.tpl" }}
</body>
</html>

View File

@ -1,19 +1,12 @@
package main
import (
"crypto/tls"
"fmt"
"net/http"
"github.com/gogf/gf/net/ghttp"
)
func main() {
c := ghttp.NewClient()
c.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
r, e := c.Clone().Get("https://127.0.0.1:8199")
fmt.Println(e)
fmt.Println(r.StatusCode)
r, err := ghttp.Get("http://127.0.0.1:8199/11111/11122")
fmt.Println(err)
fmt.Println(r.Header)
}

View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
)
func main() {
path1 := "/Users/john/Pictures/logo1.png"
path2 := "/Users/john/Pictures/logo2.png"
r, e := ghttp.Post(
"http://127.0.0.1:8199/upload",
fmt.Sprintf(`upload-file=@file:%s&upload-file=@file:%s`, path1, path2),
)
if e != nil {
glog.Error(e)
} else {
fmt.Println(string(r.ReadAll()))
r.Close()
}
}

View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
)
func main() {
path1 := "/Users/john/Pictures/logo1.png"
path2 := "/Users/john/Pictures/logo2.png"
r, e := ghttp.Post(
"http://127.0.0.1:8199/upload",
fmt.Sprintf(`upload-file[]=@file:%s&upload-file[]=@file:%s`, path1, path2),
)
if e != nil {
glog.Error(e)
} else {
fmt.Println(string(r.ReadAll()))
r.Close()
}
}

View File

@ -0,0 +1,80 @@
package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gfile"
"io"
)
// Upload uploads files to /tmp .
func Upload(r *ghttp.Request) {
saveDir := "/tmp/"
for _, item := range r.GetMultipartFiles("upload-file") {
file, err := item.Open()
if err != nil {
r.Response.Write(err)
return
}
defer file.Close()
f, err := gfile.Create(saveDir + gfile.Basename(item.Filename))
if err != nil {
r.Response.Write(err)
return
}
defer f.Close()
if _, err := io.Copy(f, file); err != nil {
r.Response.Write(err)
return
}
}
r.Response.Write("upload successfully")
}
// UploadShow shows uploading simgle file page.
func UploadShow(r *ghttp.Request) {
r.Response.Write(`
<html>
<head>
<title>GF Upload File Demo</title>
</head>
<body>
<form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="upload-file" />
<input type="submit" value="upload" />
</form>
</body>
</html>
`)
}
// UploadShowBatch shows uploading multiple files page.
func UploadShowBatch(r *ghttp.Request) {
r.Response.Write(`
<html>
<head>
<title>GF Upload Files Demo</title>
</head>
<body>
<form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="upload-file" />
<input type="file" name="upload-file" />
<input type="submit" value="upload" />
</form>
</body>
</html>
`)
}
func main() {
s := g.Server()
s.Group("/upload", func(group *ghttp.RouterGroup) {
group.ALL("/", Upload)
group.ALL("/show", UploadShow)
group.ALL("/batch", UploadShowBatch)
})
s.SetPort(8199)
s.Run()
}

View File

@ -9,7 +9,7 @@ import (
func main() {
path := "/home/john/Workspace/Go/github.com/gogf/gf/version.go"
r, e := ghttp.Post("http://127.0.0.1:8199/upload", "name=john&age=18&upload-file=@file:"+path)
r, e := ghttp.Post("http://127.0.0.1:8199/upload", "upload-file=@file:"+path)
if e != nil {
glog.Error(e)
} else {

View File

@ -4,28 +4,41 @@ import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gfile"
"io"
)
// 执行文件上传处理,上传到系统临时目录 /tmp
// Upload uploads files to /tmp .
func Upload(r *ghttp.Request) {
if f, h, e := r.FormFile("upload-file"); e == nil {
saveDir := "/tmp/"
for _, item := range r.GetMultipartFiles("upload-file") {
file, err := item.Open()
if err != nil {
r.Response.Write(err)
return
}
defer file.Close()
f, err := gfile.Create(saveDir + gfile.Basename(item.Filename))
if err != nil {
r.Response.Write(err)
return
}
defer f.Close()
name := gfile.Basename(h.Filename)
buffer := make([]byte, h.Size)
f.Read(buffer)
gfile.PutBytes("/tmp/"+name, buffer)
r.Response.Write(name + " uploaded successly")
} else {
r.Response.Write(e.Error())
if _, err := io.Copy(f, file); err != nil {
r.Response.Write(err)
return
}
}
r.Response.Write("upload successfully")
}
// 展示文件上传页面
// UploadShow shows uploading simgle file page.
func UploadShow(r *ghttp.Request) {
r.Response.Write(`
<html>
<head>
<title>上传文件</title>
<title>GF Upload File Demo</title>
</head>
<body>
<form enctype="multipart/form-data" action="/upload" method="post">
@ -37,10 +50,31 @@ func UploadShow(r *ghttp.Request) {
`)
}
// UploadShowBatch shows uploading multiple files page.
func UploadShowBatch(r *ghttp.Request) {
r.Response.Write(`
<html>
<head>
<title>GF Upload Files Demo</title>
</head>
<body>
<form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="upload-file" />
<input type="file" name="upload-file" />
<input type="submit" value="upload" />
</form>
</body>
</html>
`)
}
func main() {
s := g.Server()
s.BindHandler("/upload", Upload)
s.BindHandler("/upload/show", UploadShow)
s.Group("/upload", func(group *ghttp.RouterGroup) {
group.ALL("/", Upload)
group.ALL("/show", UploadShow)
group.ALL("/batch", UploadShowBatch)
})
s.SetPort(8199)
s.Run()
}

View File

@ -16,8 +16,8 @@ func Order(r *ghttp.Request) {
func main() {
s := g.Server()
s.Group("/api.v1", func(g *ghttp.RouterGroup) {
g.Middleware(MiddlewareCORS)
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
group.Middleware(MiddlewareCORS)
g.GET("/order", Order)
})
s.SetPort(8199)

View File

@ -18,8 +18,8 @@ func Order(r *ghttp.Request) {
func main() {
s := g.Server()
s.Group("/api.v1", func(g *ghttp.RouterGroup) {
g.Middleware(MiddlewareCORS)
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
group.Middleware(MiddlewareCORS)
g.GET("/order", Order)
})
s.SetPort(8199)

View File

@ -24,8 +24,8 @@ func Order(r *ghttp.Request) {
func main() {
s := g.Server()
s.Group("/api.v1", func(g *ghttp.RouterGroup) {
g.Middleware(MiddlewareCORS)
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
group.Middleware(MiddlewareCORS)
g.GET("/order", Order)
})
s.SetPort(8199)

View File

@ -0,0 +1,9 @@
package main
import (
"github.com/gogf/gf/net/ghttp"
)
func main() {
ghttp.PostContent("http://127.0.0.1:8199/", "array[]=1&array[]=2")
}

View File

@ -8,7 +8,7 @@ import (
func main() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request) {
g.Dump(r.GetPostMap())
g.Dump(r.GetForm("array"))
r.Response.WriteTpl("form.html")
})
s.SetPort(8199)

View File

@ -3,14 +3,16 @@ package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
)
func main() {
s := g.Server()
s.SetIndexFolder(true)
s.BindHandler("/", func(r *ghttp.Request) {
glog.Println(r.Header)
r.Response.Write("hello world")
})
s.SetPort(8199)
s.SetPort(8999)
s.Run()
}

View File

@ -2,26 +2,18 @@ package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
"github.com/gogf/gf/net/ghttp"
)
type Order struct {
gmvc.Controller
}
func (o *Order) Get() {
o.Response.Write("GET")
func Order(r *ghttp.Request) {
r.Response.Write("GET")
}
func main() {
s := g.Server()
s.BindHookHandlerByMap("/api.v1/*any", map[string]ghttp.HandlerFunc{
"BeforeServe": func(r *ghttp.Request) {
r.Response.SetAllowCrossDomainRequest("*", "PUT,GET,POST,DELETE,OPTIONS")
},
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
g.GET("/order", Order)
})
s.BindControllerRest("/api.v1/{.struct}", new(Order))
s.SetPort(8199)
s.Run()
}

View File

@ -2,26 +2,21 @@ package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/gmvc"
"github.com/gogf/gf/net/ghttp"
)
type Order2 struct {
gmvc.Controller
}
func (o *Order2) Get() {
o.Response.Write("GET")
func Order(r *ghttp.Request) {
r.Response.Write("GET")
}
func main() {
s := g.Server()
s.BindHookHandlerByMap("/api.v2/*any", map[string]ghttp.HandlerFunc{
"BeforeServe": func(r *ghttp.Request) {
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
group.Hook("/*any", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
r.Response.CORSDefault()
},
})
g.GET("/order", Order)
})
s.BindControllerRest("/api.v2/{.struct}", new(Order2))
s.SetPort(8199)
s.Run()
}

View File

@ -11,12 +11,10 @@ func main() {
p := "/:name/info/{uid}"
s := g.Server()
s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{
"BeforeServe": func(r *ghttp.Request) { glog.Println("BeforeServe") },
"AfterServe": func(r *ghttp.Request) { glog.Println("AfterServe") },
"BeforeOutput": func(r *ghttp.Request) { glog.Println("BeforeOutput") },
"AfterOutput": func(r *ghttp.Request) { glog.Println("AfterOutput") },
"BeforeClose": func(r *ghttp.Request) { glog.Println("BeforeClose") },
"AfterClose": func(r *ghttp.Request) { glog.Println("AfterClose") },
ghttp.HOOK_BEFORE_SERVE: func(r *ghttp.Request) { glog.Println(ghttp.HOOK_BEFORE_SERVE) },
ghttp.HOOK_AFTER_SERVE: func(r *ghttp.Request) { glog.Println(ghttp.HOOK_AFTER_SERVE) },
ghttp.HOOK_BEFORE_OUTPUT: func(r *ghttp.Request) { glog.Println(ghttp.HOOK_BEFORE_OUTPUT) },
ghttp.HOOK_AFTER_OUTPUT: func(r *ghttp.Request) { glog.Println(ghttp.HOOK_AFTER_OUTPUT) },
})
s.BindHandler(p, func(r *ghttp.Request) {
r.Response.Write("用户:", r.Get("name"), ", uid:", r.Get("uid"))

View File

@ -1,38 +0,0 @@
package main
import (
"fmt"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
func main() {
s := g.Server()
// 多事件回调示例事件1
pattern1 := "/:name/info"
s.BindHookHandlerByMap(pattern1, map[string]ghttp.HandlerFunc{
"BeforeServe": func(r *ghttp.Request) {
r.SetQuery("uid", "1000")
},
})
s.BindHandler(pattern1, func(r *ghttp.Request) {
r.Response.Write("用户:", r.Get("name"), ", uid:", r.GetQueryString("uid"))
})
// 多事件回调示例事件2
pattern2 := "/{object}/list/{page}.java"
s.BindHookHandlerByMap(pattern2, map[string]ghttp.HandlerFunc{
"BeforeOutput": func(r *ghttp.Request) {
r.Response.SetBuffer([]byte(
fmt.Sprintf("通过事件修改输出内容, object:%s, page:%s", r.Get("object"), r.GetRouterString("page"))),
)
},
})
s.BindHandler(pattern2, func(r *ghttp.Request) {
r.Response.Write(r.Router.Uri)
})
s.SetPort(8199)
s.Run()
}

Some files were not shown because too many files have changed in this diff Show More