├── os ├── gfile │ ├── testdata │ │ ├── dir1 │ │ │ └── file1 │ │ ├── dir2 │ │ │ └── file2 │ │ └── readline │ │ │ └── file.log │ ├── gfile_z_example_home_test.go │ ├── gfile_z_example_sort_test.go │ ├── gfile_z_example_search_test.go │ ├── gfile_z_example_time_test.go │ ├── gfile_time.go │ └── gfile_sort.go ├── gcfg │ ├── testdata │ │ ├── c1.toml │ │ ├── default │ │ │ ├── config.json │ │ │ └── config.toml │ │ ├── envfile │ │ │ └── c6.json │ │ ├── envpath │ │ │ ├── c3.toml │ │ │ └── c4.json │ │ ├── folder1 │ │ │ ├── c1.toml │ │ │ └── c2.json │ │ └── cfg-with-utf8-bom.toml │ └── gcfg_z_unit_test.go ├── gres │ ├── testdata │ │ ├── files │ │ │ ├── dir1 │ │ │ │ ├── test1 │ │ │ │ └── sub │ │ │ │ │ └── sub-test1.txt │ │ │ ├── dir2 │ │ │ │ ├── test2 │ │ │ │ └── sub │ │ │ │ │ └── sub-test2.txt │ │ │ ├── i18n-dir │ │ │ │ ├── ja │ │ │ │ │ ├── world.yaml │ │ │ │ │ └── hello.yaml │ │ │ │ ├── ru │ │ │ │ │ ├── world.ini │ │ │ │ │ └── hello.ini │ │ │ │ ├── en │ │ │ │ │ ├── hello.toml │ │ │ │ │ └── world.toml │ │ │ │ ├── zh-CN │ │ │ │ │ ├── hello.json │ │ │ │ │ └── world.json │ │ │ │ └── zh-TW │ │ │ │ │ ├── hello.xml │ │ │ │ │ └── world.xml │ │ │ ├── i18n │ │ │ │ ├── zh-CN.toml │ │ │ │ ├── zh-TW.toml │ │ │ │ ├── ja.toml │ │ │ │ ├── en.toml │ │ │ │ └── ru.toml │ │ │ ├── template │ │ │ │ ├── layout2 │ │ │ │ │ ├── footer.html │ │ │ │ │ ├── header.html │ │ │ │ │ ├── main │ │ │ │ │ │ ├── main1.html │ │ │ │ │ │ └── main2.html │ │ │ │ │ └── layout.html │ │ │ │ ├── index.html │ │ │ │ └── layout1 │ │ │ │ │ ├── footer.html │ │ │ │ │ ├── header.html │ │ │ │ │ ├── container.html │ │ │ │ │ └── layout.html │ │ │ ├── i18n-file │ │ │ │ ├── ru.ini │ │ │ │ ├── ja.yaml │ │ │ │ ├── en.toml │ │ │ │ ├── zh-CN.json │ │ │ │ └── zh-TW.xml │ │ │ ├── root │ │ │ │ ├── css │ │ │ │ │ └── style.css │ │ │ │ ├── image │ │ │ │ │ └── logo.png │ │ │ │ └── index.html │ │ │ ├── config │ │ │ │ ├── my.ini │ │ │ │ └── config.toml │ │ │ └── config-custom │ │ │ │ ├── my.ini │ │ │ │ └── config.toml │ │ └── example │ │ │ ├── files │ │ │ ├── public │ │ │ │ └── index.html │ │ │ ├── template │ │ │ │ └── index.tpl │ │ │ └── config │ │ │ │ └── config.toml │ │ │ └── boot │ │ │ └── data.go │ └── gres_instance.go ├── gview │ ├── testdata │ │ ├── config │ │ │ └── test.html │ │ ├── tpl │ │ │ └── encode.tpl │ │ ├── i18n │ │ │ ├── zh-CN.toml │ │ │ ├── zh-TW.toml │ │ │ ├── ja.toml │ │ │ ├── en.toml │ │ │ └── ru.toml │ │ └── issue1416 │ │ │ ├── gview.tpl │ │ │ └── gview copy.tpl │ ├── gview_error.go │ └── gview_instance.go ├── gcron │ ├── gcron_z_bench_test.go │ └── gcron_z_example_1_test.go ├── gsession │ ├── gsession_z_unit_test.go │ └── gsession.go ├── glog │ ├── glog_logger_writer.go │ ├── glog_z_example_test.go │ └── glog_instance.go ├── gcache │ ├── gcache_adapter_memory_item.go │ └── gcache_adapter_memory_expire_times.go ├── genv │ └── genv_must.go ├── gtime │ ├── gtime_sql.go │ ├── gtime_time_wrapper.go │ └── gtime_z_unit_feature_sql_test.go ├── gtimer │ ├── gtimer_z_example_test.go │ └── gtimer_z_bench_test.go ├── gproc │ ├── gproc_z_unit_test.go │ └── gproc_must.go ├── gctx │ ├── gctx_z_unit_test.go │ └── gctx.go ├── gstructs │ └── gstructs_z_bench_test.go ├── gcmd │ └── gcmd_scan.go ├── gbuild │ └── gbuild_z_unit_test.go ├── grpool │ └── grpool_z_bench_test.go ├── gmlock │ └── gmlock_z_bench_test.go └── gfsnotify │ └── gfsnotify_event.go ├── net ├── ghttp │ ├── testdata │ │ ├── main.html │ │ ├── static1 │ │ │ ├── index.html │ │ │ └── test.html │ │ ├── template │ │ │ ├── layout2 │ │ │ │ ├── footer.html │ │ │ │ ├── header.html │ │ │ │ ├── main │ │ │ │ │ ├── main1.html │ │ │ │ │ └── main2.html │ │ │ │ └── layout.html │ │ │ ├── basic │ │ │ │ └── index.html │ │ │ └── layout1 │ │ │ │ ├── footer.html │ │ │ │ ├── header.html │ │ │ │ ├── container.html │ │ │ │ └── layout.html │ │ ├── upload │ │ │ ├── file1.txt │ │ │ └── file2.txt │ │ └── issue1611 │ │ │ ├── header.html │ │ │ └── index │ │ │ └── layout.html │ ├── ghttp_server_admin_windows.go │ ├── ghttp_middleware_cors.go │ ├── ghttp_server_session.go │ ├── internal │ │ └── swaggerui │ │ │ └── swaggerui.go │ ├── ghttp_server_error_logger.go │ ├── ghttp_server_util.go │ ├── ghttp_server_config_route.go │ ├── ghttp_server_plugin.go │ ├── ghttp_z_bench_test.go │ ├── ghttp_request_param_router.go │ ├── ghttp_z_example_test.go │ ├── ghttp_z_unit_feature_context_test.go │ ├── ghttp_z_unit_feature_ip_test.go │ └── ghttp_z_unit_feature_request_ctx_test.go ├── gclient │ ├── testdata │ │ └── upload │ │ │ ├── file1.txt │ │ │ └── file2.txt │ └── gclient_websocket.go ├── gtcp │ ├── gtcp.go │ └── gtcp_z_example_test.go ├── gudp │ ├── gudp.go │ └── gudp_z_example_test.go ├── gsel │ ├── gsel_builder_random.go │ ├── gsel_builder_weight.go │ ├── gsel_builder_round_robin.go │ ├── gsel_builder_least_connection.go │ ├── gsel_builder.go │ ├── gsel_selector_round_robin.go │ └── gsel_selector_random.go ├── gsvc │ ├── gsvc_metadata.go │ ├── gsvc_search.go │ └── gsvc_registry.go ├── gtrace │ ├── gtrace_span.go │ ├── gtrace_tracer.go │ └── internal │ │ └── provider │ │ ├── provider_idgenerator.go │ │ └── provider.go ├── gipv6 │ └── gipv6.go └── gipv4 │ └── gipv4_mac.go ├── encoding ├── gbase64 │ └── testdata │ │ └── test ├── gjson │ ├── testdata │ │ ├── json │ │ │ └── data1.json │ │ ├── yaml │ │ │ └── data1.yaml │ │ ├── toml │ │ │ └── data1.toml │ │ └── xml │ │ │ └── data1.xml │ ├── gjson_api_config.go │ └── gjson_implements.go ├── gcompress │ ├── testdata │ │ ├── gzip │ │ │ └── file.txt │ │ └── zip │ │ │ ├── path1 │ │ │ └── 1.txt │ │ │ └── path2 │ │ │ └── 2.txt │ ├── gcompress.go │ └── gcompress_z_unit_zlib_test.go ├── gbinary │ └── gbinary_func.go └── ghash │ ├── ghash.go │ ├── ghash_djb.go │ ├── ghash_jshash.go │ ├── ghash_bkdr.go │ ├── ghash_rs.go │ ├── ghash_sdbm.go │ ├── ghash_ap.go │ └── ghash_elf.go ├── frame ├── gins │ ├── testdata │ │ ├── view2 │ │ │ ├── test.html │ │ │ └── config.toml │ │ ├── view1 │ │ │ ├── test1.html │ │ │ ├── test2.html │ │ │ └── config.toml │ │ ├── server │ │ │ └── config.yaml │ │ ├── config │ │ │ └── config.toml │ │ ├── database │ │ │ └── config.toml │ │ └── redis │ │ │ └── config.toml │ ├── gins_i18n.go │ ├── gins_resource.go │ ├── gins_config.go │ ├── gins_httpclient.go │ ├── gins_z_unit_httpclient_test.go │ └── gins_z_unit_server_test.go └── g │ ├── g_z_example_test.go │ └── g_setting.go ├── cmd └── gf │ ├── internal │ ├── consts │ │ ├── consts.go │ │ ├── consts_gen_pbentity_template.go │ │ ├── consts_gen_dao_template_entity.go │ │ └── consts_gen_dao_template_do.go │ ├── packed │ │ └── packed.go │ ├── utility │ │ ├── utils │ │ │ └── utils.go │ │ └── allyes │ │ │ └── allyes.go │ └── cmd │ │ ├── cmd_install.go │ │ └── cmd_gen.go │ ├── test │ └── testdata │ │ ├── tpls │ │ ├── tpl2.sql │ │ └── tpl1.yaml │ │ └── values.json │ ├── Makefile │ ├── go.mod │ └── LICENSE ├── i18n └── gi18n │ ├── testdata │ ├── i18n-dir │ │ ├── ja │ │ │ ├── world.yaml │ │ │ └── hello.yaml │ │ ├── ru │ │ │ ├── world.ini │ │ │ └── hello.ini │ │ ├── en │ │ │ ├── hello.toml │ │ │ └── world.toml │ │ ├── zh-CN │ │ │ ├── hello.json │ │ │ └── world.json │ │ └── zh-TW │ │ │ ├── hello.xml │ │ │ └── world.xml │ ├── i18n │ │ ├── zh-CN.toml │ │ ├── zh-TW.toml │ │ ├── en.toml │ │ ├── ja.toml │ │ └── ru.toml │ └── i18n-file │ │ ├── ja.yaml │ │ ├── ru.ini │ │ ├── en.toml │ │ ├── zh-CN.json │ │ └── zh-TW.xml │ ├── gi18n_instance.go │ └── gi18n_ctx.go ├── .gitattributes ├── version.go ├── example ├── trace │ ├── grpc_with_db │ │ ├── client │ │ │ └── config.yaml │ │ ├── sql.sql │ │ ├── protobuf │ │ │ └── user │ │ │ │ └── client.go │ │ ├── server │ │ │ └── config.yaml │ │ └── protocol │ │ │ └── user │ │ │ └── user.proto │ ├── http_with_db │ │ ├── sql.sql │ │ └── server │ │ │ └── config.yaml │ └── http │ │ ├── client │ │ └── main.go │ │ └── server │ │ └── main.go ├── httpserver │ ├── swagger │ │ ├── config.yaml │ │ └── main.go │ └── response_with_json_array │ │ ├── main.go │ │ └── controller.go ├── registry │ └── http │ │ ├── server │ │ └── main.go │ │ └── client │ │ └── main.go └── go.mod ├── contrib ├── drivers │ ├── mysql │ │ ├── go.mod │ │ └── mysql.go │ ├── pgsql │ │ └── go.mod │ ├── oracle │ │ └── go.mod │ ├── mssql │ │ └── go.mod │ ├── sqlite │ │ └── go.mod │ └── clickhouse │ │ ├── go.mod │ │ └── clickhouse.go ├── registry │ └── etcd │ │ └── go.mod └── trace │ └── jaeger │ └── go.mod ├── .gitignore ├── test └── gtest │ ├── gtest.go │ └── gtest_z_unit_test.go ├── internal ├── utils │ ├── utils.go │ ├── utils_array.go │ ├── utils_z_bench_test.go │ ├── utils_list.go │ └── utils_map.go ├── mutex │ ├── mutex_z_bench_test.go │ └── mutex.go ├── rwmutex │ └── rwmutex_z_bench_test.go └── fileinfo │ └── fileinfo.go ├── debug └── gdebug │ ├── gdebug.go │ └── gdebug_grid.go ├── container ├── garray │ ├── garray.go │ └── garray_z_bench_any_test.go ├── gtree │ └── gtree.go ├── gtype │ └── gtype.go ├── gvar │ ├── gvar_scan.go │ ├── gvar_struct.go │ └── gvar_list.go ├── gpool │ └── gpool_bench_test.go ├── gqueue │ └── gqueue_z_bench_test.go └── glist │ └── glist_z_bench_test.go ├── text ├── gstr │ ├── gstr_length.go │ ├── gstr_is.go │ ├── gstr_create.go │ ├── gstr.go │ ├── gstr_z_unit_convert_test.go │ ├── gstr_compare.go │ ├── gstr_contain.go │ └── gstr_array.go └── gregex │ └── gregex_z_bench_test.go ├── database ├── gredis │ ├── gredis_message.go │ ├── gredis_subscription.go │ ├── gredis_z_unit_config_test.go │ └── gredis_instance.go └── gdb │ ├── gdb_model_lock.go │ ├── testdata │ ├── reservedwords_table_tpl.sql │ ├── issue1412.sql │ ├── with_multiple_depends.sql │ └── issue1401.sql │ ├── gdb_schema.go │ ├── gdb_model_transaction.go │ └── gdb_z_example_test.go ├── protocol └── goai │ ├── goai_tags.go │ ├── goai_xextensions.go │ ├── goai_callback.go │ ├── goai_header.go │ ├── goai_server.go │ ├── goai_example.go │ ├── goai_components.go │ ├── goai_external_docs.go │ ├── goai_info.go │ ├── goai_mediatype.go │ └── goai_link.go ├── crypto └── gcrc32 │ ├── gcrc32.go │ └── gcrc32_z_unit_test.go ├── .gitee └── ISSUE_TEMPLATE.MD ├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE.MD ├── errors ├── gcode │ └── gcode_z_unit_test.go └── gerror │ ├── gerror_stack.go │ └── gerror_option.go ├── util ├── gconv │ ├── gconv_z_unit_unsafe_test.go │ ├── gconv_unsafe.go │ └── gconv_z_unit_custom_type_test.go ├── gvalid │ ├── gvalid_validator_rule_luhn.go │ └── gvalid_z_unit_feature_ci_test.go ├── gtag │ └── gtag_z_example_test.go ├── gutil │ ├── gutil_z_bench_test.go │ ├── gutil_z_unit_struct_test.go │ └── gutil_struct.go └── guid │ ├── guid_z_unit_test.go │ └── guid_z_bench_test.go ├── go.mod └── LICENSE /os/gfile/testdata/dir1/file1: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /os/gfile/testdata/dir2/file2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /net/ghttp/testdata/main.html: -------------------------------------------------------------------------------- 1 | main -------------------------------------------------------------------------------- /encoding/gbase64/testdata/test: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /net/ghttp/testdata/static1/index.html: -------------------------------------------------------------------------------- 1 | index -------------------------------------------------------------------------------- /net/ghttp/testdata/static1/test.html: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /frame/gins/testdata/view2/test.html: -------------------------------------------------------------------------------- 1 | test:{.name} -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout2/footer.html: -------------------------------------------------------------------------------- 1 | b -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout2/header.html: -------------------------------------------------------------------------------- 1 | a -------------------------------------------------------------------------------- /os/gcfg/testdata/c1.toml: -------------------------------------------------------------------------------- 1 | 2 | my-config = "1" -------------------------------------------------------------------------------- /os/gres/testdata/files/dir1/test1: -------------------------------------------------------------------------------- 1 | test1 content -------------------------------------------------------------------------------- /os/gres/testdata/files/dir2/test2: -------------------------------------------------------------------------------- 1 | test2 content -------------------------------------------------------------------------------- /os/gview/testdata/config/test.html: -------------------------------------------------------------------------------- 1 | name:${.name} -------------------------------------------------------------------------------- /cmd/gf/internal/consts/consts.go: -------------------------------------------------------------------------------- 1 | package consts 2 | -------------------------------------------------------------------------------- /cmd/gf/internal/packed/packed.go: -------------------------------------------------------------------------------- 1 | package packed 2 | -------------------------------------------------------------------------------- /frame/gins/testdata/view1/test1.html: -------------------------------------------------------------------------------- 1 | test1:${.name} -------------------------------------------------------------------------------- /frame/gins/testdata/view1/test2.html: -------------------------------------------------------------------------------- 1 | test2:#{.name} -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/ja/world.yaml: -------------------------------------------------------------------------------- 1 | world: "世界" -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout2/main/main1.html: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout2/main/main2.html: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /os/gcfg/testdata/default/config.json: -------------------------------------------------------------------------------- 1 | {"my-config": 2} -------------------------------------------------------------------------------- /os/gcfg/testdata/default/config.toml: -------------------------------------------------------------------------------- 1 | my-config = "1" -------------------------------------------------------------------------------- /os/gcfg/testdata/envfile/c6.json: -------------------------------------------------------------------------------- 1 | 2 | {"my-config": 6} -------------------------------------------------------------------------------- /os/gcfg/testdata/envpath/c3.toml: -------------------------------------------------------------------------------- 1 | 2 | my-config = "3" -------------------------------------------------------------------------------- /os/gcfg/testdata/envpath/c4.json: -------------------------------------------------------------------------------- 1 | 2 | {"my-config": 4} -------------------------------------------------------------------------------- /os/gcfg/testdata/folder1/c1.toml: -------------------------------------------------------------------------------- 1 | 2 | my-config = "2" -------------------------------------------------------------------------------- /os/gcfg/testdata/folder1/c2.json: -------------------------------------------------------------------------------- 1 | 2 | {"my-config": 2} -------------------------------------------------------------------------------- /os/gview/testdata/tpl/encode.tpl: -------------------------------------------------------------------------------- 1 |
{{.title}}
-------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/ru/world.ini: -------------------------------------------------------------------------------- 1 | world = "мир" -------------------------------------------------------------------------------- /net/ghttp/testdata/template/basic/index.html: -------------------------------------------------------------------------------- 1 | Name:{{.name}} -------------------------------------------------------------------------------- /os/gres/testdata/example/files/public/index.html: -------------------------------------------------------------------------------- 1 | Hello! -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/ja/world.yaml: -------------------------------------------------------------------------------- 1 | world: "世界" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/ru/world.ini: -------------------------------------------------------------------------------- 1 | world = "мир" -------------------------------------------------------------------------------- /cmd/gf/test/testdata/tpls/tpl2.sql: -------------------------------------------------------------------------------- 1 | insert into {{.sql.table}} -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/en/hello.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Hello" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/en/world.toml: -------------------------------------------------------------------------------- 1 | 2 | world = "World" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/ja/hello.yaml: -------------------------------------------------------------------------------- 1 | 2 | hello: "こんにちは" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/ru/hello.ini: -------------------------------------------------------------------------------- 1 | hello = "Привет" 2 | -------------------------------------------------------------------------------- /os/gres/testdata/files/dir1/sub/sub-test1.txt: -------------------------------------------------------------------------------- 1 | sub-test1 content -------------------------------------------------------------------------------- /os/gres/testdata/files/dir2/sub/sub-test2.txt: -------------------------------------------------------------------------------- 1 | sub-test2 content -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/ru/hello.ini: -------------------------------------------------------------------------------- 1 | hello = "Привет" -------------------------------------------------------------------------------- /os/gview/testdata/i18n/zh-CN.toml: -------------------------------------------------------------------------------- 1 | hello = "你好" 2 | world = "世界" -------------------------------------------------------------------------------- /os/gview/testdata/i18n/zh-TW.toml: -------------------------------------------------------------------------------- 1 | hello = "你好" 2 | world = "世界" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n/zh-CN.toml: -------------------------------------------------------------------------------- 1 | hello = "你好" 2 | world = "世界" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n/zh-TW.toml: -------------------------------------------------------------------------------- 1 | hello = "你好" 2 | world = "世界" -------------------------------------------------------------------------------- /os/gfile/testdata/readline/file.log: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | c 4 | d 5 | e 6 | -------------------------------------------------------------------------------- /os/gres/testdata/example/files/template/index.tpl: -------------------------------------------------------------------------------- 1 | Hello ${.name}! -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/en/hello.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Hello" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/en/world.toml: -------------------------------------------------------------------------------- 1 | 2 | world = "World" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/ja/hello.yaml: -------------------------------------------------------------------------------- 1 | 2 | hello: "こんにちは" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n/zh-CN.toml: -------------------------------------------------------------------------------- 1 | hello = "你好" 2 | world = "世界" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n/zh-TW.toml: -------------------------------------------------------------------------------- 1 | hello = "你好" 2 | world = "世界" -------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout2/footer.html: -------------------------------------------------------------------------------- 1 |

FOOTER

-------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout2/header.html: -------------------------------------------------------------------------------- 1 |

HEADER

-------------------------------------------------------------------------------- /os/gview/testdata/i18n/ja.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "こんにちは" 3 | world = "世界" -------------------------------------------------------------------------------- /encoding/gjson/testdata/json/data1.json: -------------------------------------------------------------------------------- 1 | {"name":"john", "score":"100"} -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-file/ja.yaml: -------------------------------------------------------------------------------- 1 | 2 | hello: "こんにちは" 3 | world: "世界" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-file/ru.ini: -------------------------------------------------------------------------------- 1 | hello = "Привет" 2 | world = "мир" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n/en.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Hello" 3 | world = "World" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n/ja.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "こんにちは" 3 | world = "世界" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n/ru.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Привет" 3 | world = "мир" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-file/ru.ini: -------------------------------------------------------------------------------- 1 | hello = "Привет" 2 | world = "мир" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n/ja.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "こんにちは" 3 | world = "世界" -------------------------------------------------------------------------------- /os/gres/testdata/files/template/index.html: -------------------------------------------------------------------------------- 1 | It's the index template file. -------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout2/main/main1.html: -------------------------------------------------------------------------------- 1 |

MAIN1

-------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout2/main/main2.html: -------------------------------------------------------------------------------- 1 |

MAIN2

-------------------------------------------------------------------------------- /os/gview/testdata/i18n/en.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Hello" 3 | world = "World" -------------------------------------------------------------------------------- /os/gview/testdata/i18n/ru.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Привет" 3 | world = "мир" -------------------------------------------------------------------------------- /os/gview/testdata/issue1416/gview.tpl: -------------------------------------------------------------------------------- 1 | test.tpl content, vars: {{.hello}} -------------------------------------------------------------------------------- /cmd/gf/test/testdata/tpls/tpl1.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | address: {{.server.address}} -------------------------------------------------------------------------------- /encoding/gjson/testdata/yaml/data1.yaml: -------------------------------------------------------------------------------- 1 | base: 2 | name: john 3 | score: 100 -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/zh-CN/hello.json: -------------------------------------------------------------------------------- 1 | { 2 | "hello": "你好" 3 | } -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/zh-CN/world.json: -------------------------------------------------------------------------------- 1 | { 2 | "world": "世界" 3 | } -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-file/en.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Hello" 3 | world = "World" -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout1/footer.html: -------------------------------------------------------------------------------- 1 | {{define "footer"}}3{{end}} -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout1/header.html: -------------------------------------------------------------------------------- 1 | {{define "header"}}1{{end}} -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/zh-CN/hello.json: -------------------------------------------------------------------------------- 1 | { 2 | "hello": "你好" 3 | } -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/zh-CN/world.json: -------------------------------------------------------------------------------- 1 | { 2 | "world": "世界" 3 | } -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-file/ja.yaml: -------------------------------------------------------------------------------- 1 | 2 | hello: "こんにちは" 3 | world: "世界" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n/en.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Hello" 3 | world = "World" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n/ru.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Привет" 3 | world = "мир" -------------------------------------------------------------------------------- /os/gview/testdata/issue1416/gview copy.tpl: -------------------------------------------------------------------------------- 1 | test.tpl content, vars: {{ hello }} -------------------------------------------------------------------------------- /encoding/gcompress/testdata/gzip/file.txt: -------------------------------------------------------------------------------- 1 | This is a test file for gzip compression. -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout1/container.html: -------------------------------------------------------------------------------- 1 | {{define "container"}}2{{end}} -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-file/en.toml: -------------------------------------------------------------------------------- 1 | 2 | hello = "Hello" 3 | world = "World" -------------------------------------------------------------------------------- /encoding/gjson/testdata/toml/data1.toml: -------------------------------------------------------------------------------- 1 | [base] 2 | name = "john" 3 | score = 100 -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-file/zh-CN.json: -------------------------------------------------------------------------------- 1 | { 2 | "hello": "你好", 3 | "world": "世界" 4 | } -------------------------------------------------------------------------------- /net/ghttp/testdata/upload/file1.txt: -------------------------------------------------------------------------------- 1 | file1.txt: This file is for uploading unit test case. -------------------------------------------------------------------------------- /net/ghttp/testdata/upload/file2.txt: -------------------------------------------------------------------------------- 1 | file2.txt: This file is for uploading unit test case. -------------------------------------------------------------------------------- /encoding/gcompress/testdata/zip/path1/1.txt: -------------------------------------------------------------------------------- 1 | This is a test file for zip compression purpose. -------------------------------------------------------------------------------- /net/gclient/testdata/upload/file1.txt: -------------------------------------------------------------------------------- 1 | file1.txt: This file is for uploading unit test case. -------------------------------------------------------------------------------- /net/gclient/testdata/upload/file2.txt: -------------------------------------------------------------------------------- 1 | file2.txt: This file is for uploading unit test case. -------------------------------------------------------------------------------- /os/gcfg/testdata/cfg-with-utf8-bom.toml: -------------------------------------------------------------------------------- 1 | 2 | [test] 3 | testInt=1 4 | testStr="test" 5 | -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-file/zh-CN.json: -------------------------------------------------------------------------------- 1 | { 2 | "hello": "你好", 3 | "world": "世界" 4 | } -------------------------------------------------------------------------------- /net/ghttp/testdata/issue1611/header.html: -------------------------------------------------------------------------------- 1 | {{define "header"}} 2 |

{{.header}}

3 | {{end}} -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=GO 2 | *.css linguist-language=GO 3 | *.html linguist-language=GO -------------------------------------------------------------------------------- /encoding/gcompress/testdata/zip/path2/2.txt: -------------------------------------------------------------------------------- 1 | This is an another test file for zip compression purpose. -------------------------------------------------------------------------------- /os/gres/testdata/files/root/css/style.css: -------------------------------------------------------------------------------- 1 | * { 2 | font-size: 32px; 3 | text-align: center; 4 | } -------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout1/footer.html: -------------------------------------------------------------------------------- 1 | {{define "footer"}} 2 |

FOOTER

3 | {{end}} -------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout1/header.html: -------------------------------------------------------------------------------- 1 | {{define "header"}} 2 |

HEADER

3 | {{end}} -------------------------------------------------------------------------------- /version.go: -------------------------------------------------------------------------------- 1 | package gf 2 | 3 | const VERSION = "v2.0.6" 4 | const AUTHORS = "john" 5 | -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout1/layout.html: -------------------------------------------------------------------------------- 1 | {{template "header"}}{{template "container"}}{{template "footer"}} -------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout1/container.html: -------------------------------------------------------------------------------- 1 | {{define "container"}} 2 |

CONTAINER

3 | {{end}} -------------------------------------------------------------------------------- /example/trace/grpc_with_db/client/config.yaml: -------------------------------------------------------------------------------- 1 | 2 | registry: 3 | endpoints: ["127.0.0.1:2379"] 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /frame/gins/testdata/server/config.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | address: ":8000" 3 | tempByInstanceName: 4 | address: ":8003" -------------------------------------------------------------------------------- /net/ghttp/testdata/template/layout2/layout.html: -------------------------------------------------------------------------------- 1 | {{include "header.html" .}}{{include .mainTpl .}}{{include "footer.html" .}} -------------------------------------------------------------------------------- /example/httpserver/swagger/config.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | address: ":8199" 3 | openapiPath: "/api.json" 4 | swaggerPath: "/swagger" -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/zh-TW/hello.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 你好 4 | -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-dir/zh-TW/world.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 世界 4 | -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/zh-TW/hello.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 你好 4 | -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-dir/zh-TW/world.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 世界 4 | -------------------------------------------------------------------------------- /os/gres/testdata/files/root/image/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoping378/gf/master/os/gres/testdata/files/root/image/logo.png -------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout2/layout.html: -------------------------------------------------------------------------------- 1 | {{include "header.html" .}} 2 | {{include .mainTpl .}} 3 | {{include "footer.html" .}} -------------------------------------------------------------------------------- /encoding/gjson/testdata/xml/data1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | john 4 | 100 5 | -------------------------------------------------------------------------------- /i18n/gi18n/testdata/i18n-file/zh-TW.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 你好 4 | 世界 5 | -------------------------------------------------------------------------------- /os/gres/testdata/files/config/my.ini: -------------------------------------------------------------------------------- 1 | viewpath = "/home/www/templates" 2 | [redis] 3 | disk = "127.0.0.1:6379,2" 4 | cache = "127.0.0.1:6379,3" -------------------------------------------------------------------------------- /os/gres/testdata/files/config-custom/my.ini: -------------------------------------------------------------------------------- 1 | viewpath = "/home/www/templates" 2 | [redis] 3 | disk = "127.0.0.1:6379,6" 4 | cache = "127.0.0.1:6379,7" -------------------------------------------------------------------------------- /os/gres/testdata/files/config/config.toml: -------------------------------------------------------------------------------- 1 | viewpath = "/home/www/templates" 2 | [redis] 3 | disk = "127.0.0.1:6379,0" 4 | cache = "127.0.0.1:6379,1" -------------------------------------------------------------------------------- /os/gres/testdata/files/i18n-file/zh-TW.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 你好 4 | 世界 5 | -------------------------------------------------------------------------------- /os/gres/testdata/files/config-custom/config.toml: -------------------------------------------------------------------------------- 1 | viewpath = "/home/www/templates" 2 | [redis] 3 | disk = "127.0.0.1:6379,4" 4 | cache = "127.0.0.1:6379,5" -------------------------------------------------------------------------------- /cmd/gf/test/testdata/values.json: -------------------------------------------------------------------------------- 1 | { 2 | "server": { 3 | "address": "https://goframe.org" 4 | }, 5 | "sql":{ 6 | "table": "table_name" 7 | } 8 | } -------------------------------------------------------------------------------- /frame/gins/testdata/view2/config.toml: -------------------------------------------------------------------------------- 1 | 2 | 3 | [viewer] 4 | defaultFile = "test.html" 5 | delimiters = ["{", "}"] 6 | [viewer.data] 7 | name = "test" 8 | 9 | -------------------------------------------------------------------------------- /net/ghttp/testdata/issue1611/index/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | GoFrame Layout 5 | 6 | 7 | {{template "header" .}} 8 | 9 | -------------------------------------------------------------------------------- /contrib/drivers/mysql/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/contrib/drivers/mysql/v2 2 | 3 | go 1.15 4 | 5 | require github.com/gogf/gf/v2 v2.0.0-rc 6 | 7 | replace github.com/gogf/gf/v2 => ../../../ 8 | -------------------------------------------------------------------------------- /os/gres/testdata/example/files/config/config.toml: -------------------------------------------------------------------------------- 1 | 2 | [server] 3 | Address = ":8888" 4 | ServerRoot = "public" 5 | 6 | [viewer] 7 | DefaultFile = "index.tpl" 8 | Delimiters = ["${", "}"] 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .buildpath 2 | .hgignore.swp 3 | .project 4 | .orig 5 | .swp 6 | .idea/ 7 | .settings/ 8 | .vscode/ 9 | vendor/ 10 | composer.lock 11 | gitpush.sh 12 | pkg/ 13 | bin/ 14 | cbuild 15 | **/.DS_Store 16 | .test/ 17 | main 18 | gf -------------------------------------------------------------------------------- /example/trace/grpc_with_db/sql.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS `user`; 2 | CREATE TABLE `user` ( 3 | `uid` int(10) unsigned NOT NULL AUTO_INCREMENT, 4 | `name` varchar(45) NOT NULL, 5 | PRIMARY KEY (`uid`) 6 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /example/trace/http_with_db/sql.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS `user`; 2 | CREATE TABLE `user` ( 3 | `uid` int(10) unsigned NOT NULL AUTO_INCREMENT, 4 | `name` varchar(45) NOT NULL, 5 | PRIMARY KEY (`uid`) 6 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /os/gres/testdata/files/root/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | This is the index from gres. 8 | 9 | -------------------------------------------------------------------------------- /contrib/drivers/pgsql/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/contrib/drivers/pgsql/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/gogf/gf/v2 v2.0.0-rc 7 | github.com/lib/pq v1.10.4 8 | ) 9 | 10 | replace github.com/gogf/gf/v2 => ../../../ 11 | -------------------------------------------------------------------------------- /contrib/drivers/oracle/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/contrib/drivers/oracle/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/gogf/gf/v2 v2.0.0-rc 7 | github.com/mattn/go-oci8 v0.1.1 8 | ) 9 | 10 | replace github.com/gogf/gf/v2 => ../../../ 11 | -------------------------------------------------------------------------------- /contrib/registry/etcd/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/contrib/registry/etcd/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/gogf/gf/v2 v2.0.0-rc2 7 | go.etcd.io/etcd/client/v3 v3.5.1 8 | ) 9 | 10 | replace github.com/gogf/gf/v2 => ../../../ 11 | -------------------------------------------------------------------------------- /contrib/drivers/mssql/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/contrib/drivers/mssql/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/denisenkom/go-mssqldb v0.11.0 7 | github.com/gogf/gf/v2 v2.0.0-rc 8 | ) 9 | 10 | replace github.com/gogf/gf/v2 => ../../../ 11 | -------------------------------------------------------------------------------- /contrib/drivers/sqlite/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/contrib/drivers/sqlite/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/gogf/gf/v2 v2.0.0-rc 7 | github.com/mattn/go-sqlite3 v1.14.10 8 | ) 9 | 10 | replace github.com/gogf/gf/v2 => ../../../ 11 | -------------------------------------------------------------------------------- /contrib/trace/jaeger/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/contrib/trace/jaeger/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/gogf/gf/v2 v2.0.0-rc2 7 | go.opentelemetry.io/otel/exporters/jaeger v1.3.0 8 | go.opentelemetry.io/otel/sdk v1.3.0 9 | ) 10 | 11 | replace github.com/gogf/gf/v2 => ../../../ 12 | -------------------------------------------------------------------------------- /encoding/gbinary/gbinary_func.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gbinary 8 | -------------------------------------------------------------------------------- /os/gres/testdata/files/template/layout1/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | GoFrame Layout 5 | {{template "header"}} 6 | 7 | 8 |
9 | {{template "container"}} 10 |
11 | 14 | 15 | -------------------------------------------------------------------------------- /net/gtcp/gtcp.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gtcp provides TCP server and client implementations. 8 | package gtcp 9 | -------------------------------------------------------------------------------- /net/gudp/gudp.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gudp provides UDP server and client implementations. 8 | package gudp 9 | -------------------------------------------------------------------------------- /test/gtest/gtest.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gtest provides convenient test utilities for unit testing. 8 | package gtest 9 | -------------------------------------------------------------------------------- /internal/utils/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package utils provides some utility functions for internal usage. 8 | package utils 9 | -------------------------------------------------------------------------------- /encoding/ghash/ghash.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package ghash provides some classic hash functions(uint32/uint64) in go. 8 | package ghash 9 | -------------------------------------------------------------------------------- /frame/gins/testdata/view1/config.toml: -------------------------------------------------------------------------------- 1 | 2 | 3 | [viewer] 4 | [viewer.test1] 5 | defaultFile = "test1.html" 6 | delimiters = ["${", "}"] 7 | [viewer.test1.data] 8 | name = "test1" 9 | [viewer.test2] 10 | defaultFile = "test2.html" 11 | delimiters = ["#{", "}"] 12 | [viewer.test2.data] 13 | name = "test2" 14 | 15 | -------------------------------------------------------------------------------- /debug/gdebug/gdebug.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gdebug contains facilities for programs to debug themselves while they are running. 8 | package gdebug 9 | -------------------------------------------------------------------------------- /encoding/gcompress/gcompress.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gcompress provides kinds of compression algorithms for binary/bytes data. 8 | package gcompress 9 | -------------------------------------------------------------------------------- /example/trace/http_with_db/server/config.yaml: -------------------------------------------------------------------------------- 1 | 2 | # MySQL. 3 | database: 4 | logger: 5 | level: "all" 6 | stdout: true 7 | default: 8 | link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test" 9 | debug: true 10 | 11 | # Redis. 12 | redis: 13 | default: 14 | address: 127.0.0.1:6379 15 | db: 0 16 | cache: 17 | address: 127.0.0.1:6379 18 | db: 1 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /container/garray/garray.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package garray provides most commonly used array containers which also support concurrent-safe/unsafe switch feature. 8 | package garray 9 | -------------------------------------------------------------------------------- /os/gcfg/gcfg_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" -benchmem 8 | 9 | package gcfg_test 10 | 11 | import "context" 12 | 13 | var ( 14 | ctx = context.TODO() 15 | ) 16 | -------------------------------------------------------------------------------- /container/gtree/gtree.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gtree provides concurrent-safe/unsafe tree containers. 8 | // 9 | // Some implements are from: https://github.com/emirpasic/gods 10 | package gtree 11 | -------------------------------------------------------------------------------- /cmd/gf/internal/utility/utils/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "fmt" 5 | "github.com/gogf/gf/v2/os/gproc" 6 | ) 7 | 8 | var ( 9 | // gofmtPath is the binary path of command `gofmt`. 10 | gofmtPath = gproc.SearchBinaryPath("gofmt") 11 | ) 12 | 13 | // GoFmt formats the source file using command `gofmt -w -s PATH`. 14 | func GoFmt(path string) { 15 | if gofmtPath != "" { 16 | gproc.ShellExec(fmt.Sprintf(`%s -w -s %s`, gofmtPath, path)) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contrib/drivers/clickhouse/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/contrib/drivers/clickhouse/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/ClickHouse/clickhouse-go v1.5.2 7 | github.com/davecgh/go-spew v1.1.1 // indirect 8 | github.com/kr/pretty v0.1.0 // indirect 9 | github.com/stretchr/testify v1.7.0 // indirect 10 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect 11 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /text/gstr/gstr_length.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gstr 8 | 9 | import "unicode/utf8" 10 | 11 | // LenRune returns string length of unicode. 12 | func LenRune(str string) int { 13 | return utf8.RuneCountInString(str) 14 | } 15 | -------------------------------------------------------------------------------- /contrib/drivers/clickhouse/clickhouse.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package clickhouse implements gdb.Driver, which supports operations for ClickHouse. 8 | package clickhouse 9 | 10 | import ( 11 | _ "github.com/ClickHouse/clickhouse-go" 12 | ) 13 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_server_admin_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | //go:build windows 8 | // +build windows 9 | 10 | package ghttp 11 | 12 | // registerSignalHandler does nothing on a window platform. 13 | func handleProcessSignal() { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cmd/gf/internal/utility/allyes/allyes.go: -------------------------------------------------------------------------------- 1 | package allyes 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/os/gcmd" 5 | "github.com/gogf/gf/v2/os/genv" 6 | ) 7 | 8 | const ( 9 | EnvName = "GF_CLI_ALL_YES" 10 | ) 11 | 12 | // Init initializes the package manually. 13 | func Init() { 14 | if gcmd.GetOpt("y") != nil { 15 | genv.MustSet(EnvName, "1") 16 | } 17 | } 18 | 19 | // Check checks whether option allow all yes for command. 20 | func Check() bool { 21 | return genv.Get(EnvName).String() == "1" 22 | } 23 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_middleware_cors.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp 8 | 9 | // MiddlewareCORS is a middleware handler for CORS with default options. 10 | func MiddlewareCORS(r *Request) { 11 | r.Response.CORSDefault() 12 | r.Middleware.Next() 13 | } 14 | -------------------------------------------------------------------------------- /text/gstr/gstr_is.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gstr 8 | 9 | import "github.com/gogf/gf/v2/internal/utils" 10 | 11 | // IsNumeric tests whether the given string s is numeric. 12 | func IsNumeric(s string) bool { 13 | return utils.IsNumeric(s) 14 | } 15 | -------------------------------------------------------------------------------- /example/registry/http/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/gogf/gf/contrib/registry/etcd/v2" 5 | "github.com/gogf/gf/v2/frame/g" 6 | "github.com/gogf/gf/v2/net/ghttp" 7 | "github.com/gogf/gf/v2/net/gsvc" 8 | ) 9 | 10 | func main() { 11 | gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`)) 12 | 13 | s := g.Server(`hello.svc`) 14 | s.BindHandler("/", func(r *ghttp.Request) { 15 | g.Log().Info(r.Context(), `request received`) 16 | r.Response.Write(`Hello world`) 17 | }) 18 | s.Run() 19 | } 20 | -------------------------------------------------------------------------------- /cmd/gf/internal/consts/consts_gen_pbentity_template.go: -------------------------------------------------------------------------------- 1 | package consts 2 | 3 | const TemplatePbEntityMessageContent = ` 4 | // ========================================================================== 5 | // Code generated by GoFrame CLI tool. DO NOT EDIT. 6 | // ========================================================================== 7 | 8 | syntax = "proto3"; 9 | 10 | package {PackageName}; 11 | 12 | import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 13 | 14 | {OptionContent} 15 | 16 | {EntityMessage} 17 | ` 18 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_server_session.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp 8 | 9 | import "github.com/gogf/gf/v2/os/gsession" 10 | 11 | // Session is actually an alias of gsession.Session, 12 | // which is bound to a single request. 13 | type Session = gsession.Session 14 | -------------------------------------------------------------------------------- /net/gsel/gsel_builder_random.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsel 8 | 9 | type builderRandom struct{} 10 | 11 | func NewBuilderRandom() Builder { 12 | return &builderRandom{} 13 | } 14 | 15 | func (*builderRandom) Build() Selector { 16 | return NewSelectorRandom() 17 | } 18 | -------------------------------------------------------------------------------- /net/gsel/gsel_builder_weight.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsel 8 | 9 | type builderWeight struct{} 10 | 11 | func NewBuilderWeight() Builder { 12 | return &builderWeight{} 13 | } 14 | 15 | func (*builderWeight) Build() Selector { 16 | return NewSelectorWeight() 17 | } 18 | -------------------------------------------------------------------------------- /cmd/gf/internal/consts/consts_gen_dao_template_entity.go: -------------------------------------------------------------------------------- 1 | package consts 2 | 3 | const TemplateGenDaoEntityContent = ` 4 | // ================================================================================= 5 | // Code generated by GoFrame CLI tool. DO NOT EDIT. {TplDatetimeStr} 6 | // ================================================================================= 7 | 8 | package entity 9 | 10 | {TplPackageImports} 11 | 12 | // {TplTableNameCamelCase} is the golang structure for table {TplTableName}. 13 | {TplStructDefine} 14 | ` 15 | -------------------------------------------------------------------------------- /text/gstr/gstr_create.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gstr 8 | 9 | import "strings" 10 | 11 | // Repeat returns a new string consisting of multiplier copies of the string input. 12 | func Repeat(input string, multiplier int) string { 13 | return strings.Repeat(input, multiplier) 14 | } 15 | -------------------------------------------------------------------------------- /database/gredis/gredis_message.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gredis 8 | 9 | // Message received as result of a PUBLISH command issued by another client. 10 | type Message struct { 11 | Channel string 12 | Pattern string 13 | Payload string 14 | PayloadSlice []string 15 | } 16 | -------------------------------------------------------------------------------- /cmd/gf/internal/consts/consts_gen_dao_template_do.go: -------------------------------------------------------------------------------- 1 | package consts 2 | 3 | const TemplateGenDaoDoContent = ` 4 | // ================================================================================= 5 | // Code generated by GoFrame CLI tool. DO NOT EDIT. {TplDatetimeStr} 6 | // ================================================================================= 7 | 8 | package do 9 | 10 | {TplPackageImports} 11 | 12 | // {TplTableNameCamelCase} is the golang structure of table {TplTableName} for DAO operations like Where/Data. 13 | {TplStructDefine} 14 | ` 15 | -------------------------------------------------------------------------------- /net/gsel/gsel_builder_round_robin.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsel 8 | 9 | type builderRoundRobin struct{} 10 | 11 | func NewBuilderRoundRobin() Builder { 12 | return &builderRoundRobin{} 13 | } 14 | 15 | func (*builderRoundRobin) Build() Selector { 16 | return NewSelectorRoundRobin() 17 | } 18 | -------------------------------------------------------------------------------- /container/gtype/gtype.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gtype provides high performance and concurrent-safe basic variable types. 8 | package gtype 9 | 10 | // New is alias of NewInterface. 11 | // See NewInterface. 12 | func New(value ...interface{}) *Interface { 13 | return NewInterface(value...) 14 | } 15 | -------------------------------------------------------------------------------- /text/gstr/gstr.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gstr provides functions for string handling. 8 | package gstr 9 | 10 | const ( 11 | // NotFoundIndex is the position index for string not found in searching functions. 12 | NotFoundIndex = -1 13 | ) 14 | 15 | const ( 16 | defaultSuffixForStrLimit = "..." 17 | ) 18 | -------------------------------------------------------------------------------- /frame/gins/gins_i18n.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gins 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/i18n/gi18n" 11 | ) 12 | 13 | // I18n returns an instance of gi18n.Manager. 14 | // The parameter `name` is the name for the instance. 15 | func I18n(name ...string) *gi18n.Manager { 16 | return gi18n.Instance(name...) 17 | } 18 | -------------------------------------------------------------------------------- /frame/gins/gins_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gins 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/os/gres" 11 | ) 12 | 13 | // Resource returns an instance of Resource. 14 | // The parameter `name` is the name for the instance. 15 | func Resource(name ...string) *gres.Resource { 16 | return gres.Instance(name...) 17 | } 18 | -------------------------------------------------------------------------------- /net/gsel/gsel_builder_least_connection.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsel 8 | 9 | type builderLeastConnection struct{} 10 | 11 | func NewBuilderLeastConnection() Builder { 12 | return &builderLeastConnection{} 13 | } 14 | 15 | func (*builderLeastConnection) Build() Selector { 16 | return NewSelectorLeastConnection() 17 | } 18 | -------------------------------------------------------------------------------- /example/registry/http/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/gogf/gf/contrib/registry/etcd/v2" 8 | "github.com/gogf/gf/v2/frame/g" 9 | "github.com/gogf/gf/v2/net/gsvc" 10 | "github.com/gogf/gf/v2/os/gctx" 11 | ) 12 | 13 | func main() { 14 | gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`)) 15 | 16 | for i := 0; i < 100; i++ { 17 | res, err := g.Client().Get(gctx.New(), `http://hello.svc/`) 18 | if err != nil { 19 | panic(err) 20 | } 21 | fmt.Println(res.ReadAllString()) 22 | res.Close() 23 | time.Sleep(time.Second) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /frame/gins/gins_config.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gins 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/os/gcfg" 11 | ) 12 | 13 | // Config returns an instance of View with default settings. 14 | // The parameter `name` is the name for the instance. 15 | func Config(name ...string) *gcfg.Config { 16 | return gcfg.Instance(name...) 17 | } 18 | -------------------------------------------------------------------------------- /os/gfile/gfile_z_example_home_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gfile_test 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/gogf/gf/v2/os/gfile" 13 | ) 14 | 15 | func ExampleHome() { 16 | // user's home directory 17 | homePath, _ := gfile.Home() 18 | fmt.Println(homePath) 19 | 20 | // May Output: 21 | // C:\Users\hailaz 22 | } 23 | -------------------------------------------------------------------------------- /os/gcron/gcron_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gcron_test 8 | 9 | import ( 10 | "context" 11 | "testing" 12 | 13 | "github.com/gogf/gf/v2/os/gcron" 14 | ) 15 | 16 | func Benchmark_Add(b *testing.B) { 17 | for i := 0; i < b.N; i++ { 18 | gcron.Add(ctx, "1 1 1 1 1 1", func(ctx context.Context) { 19 | 20 | }) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/trace/grpc_with_db/protobuf/user/client.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "google.golang.org/grpc" 5 | 6 | "github.com/gogf/katyusha/krpc" 7 | ) 8 | 9 | const ( 10 | ServiceName = "demo" 11 | ) 12 | 13 | type Client struct { 14 | conn *grpc.ClientConn 15 | } 16 | 17 | func NewClient(options ...grpc.DialOption) (*Client, error) { 18 | conn, err := krpc.Client.NewGrpcClientConn(ServiceName, options...) 19 | if err != nil { 20 | return nil, err 21 | } 22 | return &Client{conn: conn}, nil 23 | } 24 | 25 | func (c *Client) User() UserClient { 26 | return NewUserClient(c.conn) 27 | } 28 | -------------------------------------------------------------------------------- /example/httpserver/response_with_json_array/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/gogf/gf/v2/net/ghttp" 6 | ) 7 | 8 | func main() { 9 | s := g.Server() 10 | s.Group("/", func(group *ghttp.RouterGroup) { 11 | group.Middleware(ghttp.MiddlewareHandlerResponse) 12 | group.Bind( 13 | User, 14 | ) 15 | }) 16 | oai := s.GetOpenApi() 17 | oai.Config.CommonResponse = ghttp.DefaultHandlerResponse{} 18 | oai.Config.CommonResponseDataField = "Data" 19 | s.SetOpenApiPath("/api") 20 | s.SetSwaggerPath("/swagger") 21 | s.SetPort(8199) 22 | s.Run() 23 | } 24 | -------------------------------------------------------------------------------- /os/gsession/gsession_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsession 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/test/gtest" 13 | ) 14 | 15 | func Test_NewSessionId(t *testing.T) { 16 | gtest.C(t, func(t *gtest.T) { 17 | id1 := NewSessionId() 18 | id2 := NewSessionId() 19 | t.AssertNE(id1, id2) 20 | t.Assert(len(id1), 32) 21 | }) 22 | } 23 | -------------------------------------------------------------------------------- /cmd/gf/Makefile: -------------------------------------------------------------------------------- 1 | 2 | pack: pack.template-single pack.template-mono 3 | 4 | pack.template-single: 5 | @rm -fr temp 6 | @mkdir temp || exit 0 7 | @cd temp && git clone https://github.com/gogf/template-single 8 | @rm -fr temp/template-single/.git 9 | @cd temp && gf pack template-single ../internal/packed/template-single.go -n=packed -y 10 | @rm -fr temp 11 | 12 | pack.template-mono: 13 | @rm -fr temp 14 | @mkdir temp || exit 0 15 | @cd temp && git clone https://github.com/gogf/template-mono 16 | @rm -fr temp/template-mono/.git 17 | @cd temp && gf pack template-mono ../internal/packed/template-mono.go -n=packed -y 18 | @rm -fr temp -------------------------------------------------------------------------------- /cmd/gf/internal/cmd/cmd_install.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/gogf/gf/cmd/gf/v2/internal/service" 7 | "github.com/gogf/gf/v2/frame/g" 8 | ) 9 | 10 | var ( 11 | Install = cInstall{} 12 | ) 13 | 14 | type cInstall struct { 15 | g.Meta `name:"install" brief:"install gf binary to system (might need root/admin permission)"` 16 | } 17 | 18 | type cInstallInput struct { 19 | g.Meta `name:"install"` 20 | } 21 | type cInstallOutput struct{} 22 | 23 | func (c cInstall) Index(ctx context.Context, in cInstallInput) (out *cInstallOutput, err error) { 24 | err = service.Install.Run(ctx) 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /text/gstr/gstr_z_unit_convert_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" 8 | 9 | package gstr_test 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/gogf/gf/v2/test/gtest" 15 | "github.com/gogf/gf/v2/text/gstr" 16 | ) 17 | 18 | func Test_OctStr(t *testing.T) { 19 | gtest.C(t, func(t *gtest.T) { 20 | t.Assert(gstr.OctStr(`\346\200\241`), "怡") 21 | }) 22 | } 23 | -------------------------------------------------------------------------------- /os/glog/glog_logger_writer.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package glog 8 | 9 | import ( 10 | "bytes" 11 | "context" 12 | ) 13 | 14 | // Write implements the io.Writer interface. 15 | // It just prints the content using Print. 16 | func (l *Logger) Write(p []byte) (n int, err error) { 17 | l.Header(false).Print(context.TODO(), string(bytes.TrimRight(p, "\r\n"))) 18 | return len(p), nil 19 | } 20 | -------------------------------------------------------------------------------- /example/httpserver/response_with_json_array/controller.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/gogf/gf/v2/frame/g" 7 | ) 8 | 9 | type Req struct { 10 | g.Meta `path:"/user" method:"get"` 11 | } 12 | type Res []Item 13 | 14 | type Item struct { 15 | Id int64 16 | Name string 17 | } 18 | 19 | var ( 20 | User = cUser{} 21 | ) 22 | 23 | type cUser struct{} 24 | 25 | func (c *cUser) GetList(ctx context.Context, req *Req) (res *Res, err error) { 26 | res = &Res{ 27 | {Id: 1, Name: "john"}, 28 | {Id: 2, Name: "smith"}, 29 | {Id: 3, Name: "alice"}, 30 | {Id: 4, Name: "katyusha"}, 31 | } 32 | return 33 | } 34 | -------------------------------------------------------------------------------- /example/trace/grpc_with_db/server/config.yaml: -------------------------------------------------------------------------------- 1 | 2 | registry: 3 | endpoints: ["127.0.0.1:2379"] 4 | 5 | grpcserver: 6 | name: "demo" 7 | logStdout: true 8 | errorLogEnabled: true 9 | accessLogEnabled: true 10 | errorStack: true 11 | 12 | # MySQL. 13 | database: 14 | logger: 15 | level: "all" 16 | stdout: true 17 | default: 18 | link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test" 19 | debug: true 20 | 21 | # Redis. 22 | redis: 23 | default: 24 | address: 127.0.0.1:6379 25 | db: 0 26 | cache: 27 | address: 127.0.0.1:6379 28 | db: 1 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /frame/g/g_z_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package g_test 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/frame/g" 11 | "github.com/gogf/gf/v2/net/ghttp" 12 | ) 13 | 14 | func ExampleServer() { 15 | // A hello world example. 16 | s := g.Server() 17 | s.BindHandler("/", func(r *ghttp.Request) { 18 | r.Response.Write("hello world") 19 | }) 20 | s.SetPort(8999) 21 | s.Run() 22 | } 23 | -------------------------------------------------------------------------------- /net/ghttp/internal/swaggerui/swaggerui.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package swaggerui provides packed swagger ui static files using resource manager. 8 | // 9 | // Files from: 10 | // https://github.com/Redocly/redoc 11 | // https://www.jsdelivr.com/package/npm/redoc 12 | // 13 | // Pack command: 14 | // gf pack redoc.standalone.js swaggerui-redoc.go -n=swaggerui -p=/goframe/swaggerui 15 | package swaggerui 16 | -------------------------------------------------------------------------------- /example/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/example 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/gogf/gf/contrib/registry/etcd/v2 v2.0.0-rc2 7 | github.com/gogf/gf/contrib/trace/jaeger/v2 v2.0.0-rc2 8 | github.com/gogf/gf/v2 v2.0.0-rc2.0.20220128082344-48b5f3789470 9 | github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 10 | github.com/gogo/protobuf v1.3.2 11 | github.com/golang/protobuf v1.5.2 12 | google.golang.org/grpc v1.44.0 13 | ) 14 | 15 | replace ( 16 | github.com/gogf/gf/contrib/registry/etcd/v2 => ../contrib/registry/etcd/ 17 | github.com/gogf/gf/contrib/trace/jaeger/v2 => ../contrib/trace/jaeger/ 18 | github.com/gogf/gf/v2 => ../ 19 | ) 20 | -------------------------------------------------------------------------------- /protocol/goai/goai_tags.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | // Tags is specified by OpenAPI/Swagger 3.0 standard. 10 | type Tags []Tag 11 | 12 | // Tag is specified by OpenAPI/Swagger 3.0 standard. 13 | type Tag struct { 14 | Name string `json:"name,omitempty"` 15 | Description string `json:"description,omitempty"` 16 | ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` 17 | } 18 | -------------------------------------------------------------------------------- /net/gtcp/gtcp_z_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gtcp_test 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/gogf/gf/v2/net/gtcp" 13 | ) 14 | 15 | func ExampleGetFreePort() { 16 | fmt.Println(gtcp.GetFreePort()) 17 | 18 | // May Output: 19 | // 57429 20 | } 21 | 22 | func ExampleGetFreePorts() { 23 | fmt.Println(gtcp.GetFreePorts(2)) 24 | 25 | // May Output: 26 | // [57743 57744] 27 | } 28 | -------------------------------------------------------------------------------- /net/gudp/gudp_z_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gudp_test 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/gogf/gf/v2/net/gudp" 13 | ) 14 | 15 | func ExampleGetFreePort() { 16 | fmt.Println(gudp.GetFreePort()) 17 | 18 | // May Output: 19 | // 57429 20 | } 21 | 22 | func ExampleGetFreePorts() { 23 | fmt.Println(gudp.GetFreePorts(2)) 24 | 25 | // May Output: 26 | // [57743 57744] 27 | } 28 | -------------------------------------------------------------------------------- /os/gcron/gcron_z_example_1_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gcron_test 8 | 9 | import ( 10 | "context" 11 | "time" 12 | 13 | "github.com/gogf/gf/v2/os/gcron" 14 | "github.com/gogf/gf/v2/os/glog" 15 | ) 16 | 17 | func Example_cronAddSingleton() { 18 | gcron.AddSingleton(ctx, "* * * * * *", func(ctx context.Context) { 19 | glog.Print(context.TODO(), "doing") 20 | time.Sleep(2 * time.Second) 21 | }) 22 | select {} 23 | } 24 | -------------------------------------------------------------------------------- /frame/g/g_setting.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package g 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/internal/intlog" 11 | ) 12 | 13 | // SetDebug enables/disables the GoFrame internal logging manually. 14 | // Note that this function is not concurrent safe, be aware of the DATA RACE, 15 | // which means you should call this function in your boot but not the runtime. 16 | func SetDebug(enabled bool) { 17 | intlog.SetEnabled(enabled) 18 | } 19 | -------------------------------------------------------------------------------- /os/gcache/gcache_adapter_memory_item.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gcache 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/os/gtime" 11 | ) 12 | 13 | // IsExpired checks whether `item` is expired. 14 | func (item *adapterMemoryItem) IsExpired() bool { 15 | // Note that it should use greater than or equal judgement here 16 | // imagining that the cache time is only 1 millisecond. 17 | 18 | return item.e < gtime.TimestampMilli() 19 | } 20 | -------------------------------------------------------------------------------- /os/genv/genv_must.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package genv 8 | 9 | // MustSet performs as Set, but it panics if any error occurs. 10 | func MustSet(key, value string) { 11 | if err := Set(key, value); err != nil { 12 | panic(err) 13 | } 14 | } 15 | 16 | // MustRemove performs as Remove, but it panics if any error occurs. 17 | func MustRemove(key ...string) { 18 | if err := Remove(key...); err != nil { 19 | panic(err) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /os/glog/glog_z_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package glog_test 8 | 9 | import ( 10 | "context" 11 | 12 | "github.com/gogf/gf/v2/frame/g" 13 | ) 14 | 15 | func Example_context() { 16 | ctx := context.WithValue(context.Background(), "Trace-Id", "123456789") 17 | g.Log().Error(ctx, "runtime error") 18 | 19 | // May Output: 20 | // 2020-06-08 20:17:03.630 [ERRO] {Trace-Id: 123456789} runtime error 21 | // Stack: 22 | // ... 23 | } 24 | -------------------------------------------------------------------------------- /crypto/gcrc32/gcrc32.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gcrc32 provides useful API for CRC32 encryption algorithms. 8 | package gcrc32 9 | 10 | import ( 11 | "hash/crc32" 12 | 13 | "github.com/gogf/gf/v2/util/gconv" 14 | ) 15 | 16 | // Encrypt encrypts any type of variable using CRC32 algorithms. 17 | // It uses gconv package to convert `v` to its bytes type. 18 | func Encrypt(v interface{}) uint32 { 19 | return crc32.ChecksumIEEE(gconv.Bytes(v)) 20 | } 21 | -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE.MD: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ### 1. 您当前使用的`Go`版本,及系统版本、系统架构? 7 | 8 | 9 | 10 | 11 | ### 2. 您当前使用的`GoFrame`框架版本? 12 | 13 | 14 | 15 | 16 | ### 3. 更新到最新的框架版本是否能够解决问题? 17 | 18 | 19 | 20 | 21 | ### 4. 问题描述? 22 | 23 | 27 | 28 | 29 | 30 | ### 5. 您期望得到的结果? 31 | 32 | 33 | 34 | ### 6. 您实际得到的结果? 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /encoding/gjson/gjson_api_config.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gjson 8 | 9 | // SetSplitChar sets the separator char for hierarchical data access. 10 | func (j *Json) SetSplitChar(char byte) { 11 | j.mu.Lock() 12 | j.c = char 13 | j.mu.Unlock() 14 | } 15 | 16 | // SetViolenceCheck enables/disables violence check for hierarchical data access. 17 | func (j *Json) SetViolenceCheck(enabled bool) { 18 | j.mu.Lock() 19 | j.vc = enabled 20 | j.mu.Unlock() 21 | } 22 | -------------------------------------------------------------------------------- /net/gsvc/gsvc_metadata.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsvc 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/container/gvar" 11 | ) 12 | 13 | // Set sets key-value pair into metadata. 14 | func (m Metadata) Set(key string, value string) { 15 | m[key] = value 16 | } 17 | 18 | // Get retrieves and returns value of specified key as gvar. 19 | func (m Metadata) Get(key string) *gvar.Var { 20 | if v, ok := m[key]; ok { 21 | return gvar.New(v) 22 | } 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: https://github.com/gogf/gf#donators 13 | -------------------------------------------------------------------------------- /database/gdb/gdb_model_lock.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gdb 8 | 9 | // LockUpdate sets the lock for update for current operation. 10 | func (m *Model) LockUpdate() *Model { 11 | model := m.getModel() 12 | model.lockInfo = "FOR UPDATE" 13 | return model 14 | } 15 | 16 | // LockShared sets the lock in share mode for current operation. 17 | func (m *Model) LockShared() *Model { 18 | model := m.getModel() 19 | model.lockInfo = "LOCK IN SHARE MODE" 20 | return model 21 | } 22 | -------------------------------------------------------------------------------- /os/gtime/gtime_sql.go: -------------------------------------------------------------------------------- 1 | package gtime 2 | 3 | import ( 4 | "database/sql/driver" 5 | ) 6 | 7 | // Scan implements interface used by Scan in package database/sql for Scanning value 8 | // from database to local golang variable. 9 | func (t *Time) Scan(value interface{}) error { 10 | if t == nil { 11 | return nil 12 | } 13 | newTime := New(value) 14 | *t = *newTime 15 | return nil 16 | } 17 | 18 | // Value is the interface providing the Value method for package database/sql/driver 19 | // for retrieving value from golang variable to database. 20 | func (t *Time) Value() (driver.Value, error) { 21 | if t == nil { 22 | return nil, nil 23 | } 24 | if t.IsZero() { 25 | return nil, nil 26 | } 27 | return t.Time, nil 28 | } 29 | -------------------------------------------------------------------------------- /errors/gcode/gcode_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gcode_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/errors/gcode" 13 | "github.com/gogf/gf/v2/test/gtest" 14 | ) 15 | 16 | func Test_Nil(t *testing.T) { 17 | gtest.C(t, func(t *gtest.T) { 18 | c := gcode.New(1, "custom error", "detailed description") 19 | t.Assert(c.Code(), 1) 20 | t.Assert(c.Message(), "custom error") 21 | t.Assert(c.Detail(), "detailed description") 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /net/gsel/gsel_builder.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsel 8 | 9 | // defaultBuilder is the default Builder for globally used purpose. 10 | var defaultBuilder = NewBuilderRoundRobin() 11 | 12 | // SetBuilder sets the default builder for globally used purpose. 13 | func SetBuilder(builder Builder) { 14 | defaultBuilder = builder 15 | } 16 | 17 | // GetBuilder returns the default builder for globally used purpose. 18 | func GetBuilder() Builder { 19 | return defaultBuilder 20 | } 21 | -------------------------------------------------------------------------------- /protocol/goai/goai_xextensions.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/text/gstr" 11 | ) 12 | 13 | // XExtensions stores the `x-` custom extensions. 14 | type XExtensions map[string]interface{} 15 | 16 | func (oai *OpenApiV3) tagMapToXExtensions(tagMap map[string]string, extensions XExtensions) { 17 | for k, v := range tagMap { 18 | if gstr.HasPrefix(k, "x-") || gstr.HasPrefix(k, "X-") { 19 | extensions[k] = v 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cmd/gf/internal/cmd/cmd_gen.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/gogf/gf/v2/util/gtag" 6 | ) 7 | 8 | var ( 9 | Gen = cGen{} 10 | ) 11 | 12 | type cGen struct { 13 | g.Meta `name:"gen" brief:"{cGenBrief}" dc:"{cGenDc}"` 14 | } 15 | 16 | const ( 17 | cGenBrief = `automatically generate go files for dao/do/entity/pb/pbentity` 18 | cGenDc = ` 19 | The "gen" command is designed for multiple generating purposes. 20 | It's currently supporting generating go files for ORM models, protobuf and protobuf entity files. 21 | Please use "gf gen dao -h" for specified type help. 22 | ` 23 | ) 24 | 25 | func init() { 26 | gtag.Sets(g.MapStrStr{ 27 | `cGenBrief`: cGenBrief, 28 | `cGenDc`: cGenDc, 29 | }) 30 | } 31 | -------------------------------------------------------------------------------- /contrib/drivers/mysql/mysql.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package mysql implements gdb.Driver, which supports operations for MySQL. 8 | package mysql 9 | 10 | import ( 11 | "github.com/gogf/gf/v2/database/gdb" 12 | ) 13 | 14 | func init() { 15 | if err := gdb.Register(`mysql`, New()); err != nil { 16 | panic(err) 17 | } 18 | } 19 | 20 | // New create and returns a driver that implements gdb.Driver, which supports operations for MySQL. 21 | func New() gdb.Driver { 22 | return &gdb.DriverMysql{} 23 | } 24 | -------------------------------------------------------------------------------- /container/gvar/gvar_scan.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gvar 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/util/gconv" 11 | ) 12 | 13 | // Scan automatically checks the type of `pointer` and converts `params` to `pointer`. It supports `pointer` 14 | // with type of `*map/*[]map/*[]*map/*struct/**struct/*[]struct/*[]*struct` for converting. 15 | // 16 | // See gconv.Scan. 17 | func (v *Var) Scan(pointer interface{}, mapping ...map[string]string) error { 18 | return gconv.Scan(v.Val(), pointer, mapping...) 19 | } 20 | -------------------------------------------------------------------------------- /util/gconv/gconv_z_unit_unsafe_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gconv_test 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/test/gtest" 11 | "github.com/gogf/gf/v2/util/gconv" 12 | "testing" 13 | ) 14 | 15 | func Test_Unsafe(t *testing.T) { 16 | gtest.C(t, func(t *gtest.T) { 17 | s := "I love 小泽玛利亚" 18 | t.AssertEQ(gconv.UnsafeStrToBytes(s), []byte(s)) 19 | }) 20 | 21 | gtest.C(t, func(t *gtest.T) { 22 | b := []byte("I love 小泽玛利亚") 23 | t.AssertEQ(gconv.UnsafeBytesToStr(b), string(b)) 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /text/gstr/gstr_compare.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gstr 8 | 9 | import "strings" 10 | 11 | // Compare returns an integer comparing two strings lexicographically. 12 | // The result will be 0 if a==b, -1 if a < b, and +1 if a > b. 13 | func Compare(a, b string) int { 14 | return strings.Compare(a, b) 15 | } 16 | 17 | // Equal reports whether `a` and `b`, interpreted as UTF-8 strings, 18 | // are equal under Unicode case-folding, case-insensitively. 19 | func Equal(a, b string) bool { 20 | return strings.EqualFold(a, b) 21 | } 22 | -------------------------------------------------------------------------------- /internal/utils/utils_array.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package utils 8 | 9 | import "reflect" 10 | 11 | // IsArray checks whether given value is array/slice. 12 | // Note that it uses reflect internally implementing this feature. 13 | func IsArray(value interface{}) bool { 14 | rv := reflect.ValueOf(value) 15 | kind := rv.Kind() 16 | if kind == reflect.Ptr { 17 | rv = rv.Elem() 18 | kind = rv.Kind() 19 | } 20 | switch kind { 21 | case reflect.Array, reflect.Slice: 22 | return true 23 | default: 24 | return false 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /os/gview/gview_error.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gview 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/os/gcmd" 11 | ) 12 | 13 | const ( 14 | // commandEnvKeyForErrorPrint is used to specify the key controlling error printing to stdout. 15 | // This error is designed not to be returned by functions. 16 | commandEnvKeyForErrorPrint = "gf.gview.errorprint" 17 | ) 18 | 19 | // errorPrint checks whether printing error to stdout. 20 | func errorPrint() bool { 21 | return gcmd.GetOptWithEnv(commandEnvKeyForErrorPrint, true).Bool() 22 | } 23 | -------------------------------------------------------------------------------- /cmd/gf/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/cmd/gf/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/gogf/gf/contrib/drivers/mssql/v2 v2.0.0-rc2 7 | github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.0.0-rc2 8 | github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.0.0-rc2 9 | github.com/gogf/gf/v2 v2.0.0 10 | github.com/longbridgeapp/sqlparser v0.3.1 // indirect 11 | github.com/olekukonko/tablewriter v0.0.5 12 | github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 // indirect 13 | ) 14 | 15 | replace ( 16 | github.com/gogf/gf/contrib/drivers/mssql/v2 => ../../contrib/drivers/mssql/ 17 | github.com/gogf/gf/contrib/drivers/pgsql/v2 => ../../contrib/drivers/pgsql/ 18 | github.com/gogf/gf/contrib/drivers/sqlite/v2 => ../../contrib/drivers/sqlite/ 19 | github.com/gogf/gf/v2 => ../../ 20 | ) 21 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gogf/gf/v2 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/BurntSushi/toml v0.4.1 7 | github.com/clbanning/mxj/v2 v2.5.5 8 | github.com/fatih/color v1.13.0 9 | github.com/fsnotify/fsnotify v1.5.1 10 | github.com/go-redis/redis/v8 v8.11.4 11 | github.com/go-sql-driver/mysql v1.6.0 12 | github.com/gorilla/websocket v1.5.0 13 | github.com/grokify/html-strip-tags-go v0.0.1 14 | github.com/longbridgeapp/sqlparser v0.3.1 15 | github.com/olekukonko/tablewriter v0.0.5 16 | go.opentelemetry.io/otel v1.0.0 17 | go.opentelemetry.io/otel/sdk v1.0.0 18 | go.opentelemetry.io/otel/trace v1.0.0 19 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 20 | golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 21 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b 22 | ) 23 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_server_error_logger.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp 8 | 9 | import ( 10 | "bytes" 11 | "context" 12 | 13 | "github.com/gogf/gf/v2/os/glog" 14 | ) 15 | 16 | // errorLogger is the error logging logger for underlying net/http.Server. 17 | type errorLogger struct { 18 | logger *glog.Logger 19 | } 20 | 21 | // Write implements the io.Writer interface. 22 | func (l *errorLogger) Write(p []byte) (n int, err error) { 23 | l.logger.Skip(1).Error(context.TODO(), string(bytes.TrimRight(p, "\r\n"))) 24 | return len(p), nil 25 | } 26 | -------------------------------------------------------------------------------- /net/gtrace/gtrace_span.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gtrace 8 | 9 | import ( 10 | "context" 11 | 12 | "go.opentelemetry.io/otel/trace" 13 | ) 14 | 15 | // Span warps trace.Span for compatibility and extension. 16 | type Span struct { 17 | trace.Span 18 | } 19 | 20 | // NewSpan creates a span using default tracer. 21 | func NewSpan(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, *Span) { 22 | ctx, span := NewTracer().Start(ctx, spanName, opts...) 23 | return ctx, &Span{ 24 | Span: span, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /os/gtimer/gtimer_z_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gtimer_test 8 | 9 | import ( 10 | "context" 11 | "fmt" 12 | "time" 13 | 14 | "github.com/gogf/gf/v2/os/gtimer" 15 | ) 16 | 17 | func Example_add() { 18 | var ( 19 | ctx = context.Background() 20 | now = time.Now() 21 | interval = 1400 * time.Millisecond 22 | ) 23 | gtimer.Add(ctx, interval, func(ctx context.Context) { 24 | fmt.Println(time.Now(), time.Duration(time.Now().UnixNano()-now.UnixNano())) 25 | now = time.Now() 26 | }) 27 | 28 | select {} 29 | } 30 | -------------------------------------------------------------------------------- /protocol/goai/goai_callback.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/internal/json" 11 | ) 12 | 13 | // Callback is specified by OpenAPI/Swagger standard version 3.0. 14 | type Callback map[string]*Path 15 | 16 | type Callbacks map[string]*CallbackRef 17 | 18 | type CallbackRef struct { 19 | Ref string 20 | Value *Callback 21 | } 22 | 23 | func (r CallbackRef) MarshalJSON() ([]byte, error) { 24 | if r.Ref != "" { 25 | return formatRefToBytes(r.Ref), nil 26 | } 27 | return json.Marshal(r.Value) 28 | } 29 | -------------------------------------------------------------------------------- /encoding/ghash/ghash_djb.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghash 8 | 9 | // DJB implements the classic DJB hash algorithm for 32 bits. 10 | func DJB(str []byte) uint32 { 11 | var hash uint32 = 5381 12 | for i := 0; i < len(str); i++ { 13 | hash += (hash << 5) + uint32(str[i]) 14 | } 15 | return hash 16 | } 17 | 18 | // DJB64 implements the classic DJB hash algorithm for 64 bits. 19 | func DJB64(str []byte) uint64 { 20 | var hash uint64 = 5381 21 | for i := 0; i < len(str); i++ { 22 | hash += (hash << 5) + uint64(str[i]) 23 | } 24 | return hash 25 | } 26 | -------------------------------------------------------------------------------- /net/gtrace/gtrace_tracer.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gtrace 8 | 9 | import ( 10 | "go.opentelemetry.io/otel" 11 | "go.opentelemetry.io/otel/trace" 12 | ) 13 | 14 | // Tracer warps trace.Tracer for compatibility and extension. 15 | type Tracer struct { 16 | trace.Tracer 17 | } 18 | 19 | // NewTracer Tracer is a short function for retrieving Tracer. 20 | func NewTracer(name ...string) *Tracer { 21 | tracerName := "" 22 | if len(name) > 0 { 23 | tracerName = name[0] 24 | } 25 | return &Tracer{ 26 | Tracer: otel.Tracer(tracerName), 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_server_util.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp 8 | 9 | import "net/http" 10 | 11 | // WrapF is a helper function for wrapping http.HandlerFunc and returns a ghttp.HandlerFunc. 12 | func WrapF(f http.HandlerFunc) HandlerFunc { 13 | return func(r *Request) { 14 | f(r.Response.Writer, r.Request) 15 | } 16 | } 17 | 18 | // WrapH is a helper function for wrapping http.Handler and returns a ghttp.HandlerFunc. 19 | func WrapH(h http.Handler) HandlerFunc { 20 | return func(r *Request) { 21 | h.ServeHTTP(r.Response.Writer, r.Request) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /internal/mutex/mutex_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package mutex_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/internal/mutex" 13 | ) 14 | 15 | var ( 16 | safeLock = mutex.New(false) 17 | unsafeLock = mutex.New(true) 18 | ) 19 | 20 | func Benchmark_Safe_LockUnlock(b *testing.B) { 21 | for i := 0; i < b.N; i++ { 22 | safeLock.Lock() 23 | safeLock.Unlock() 24 | } 25 | } 26 | 27 | func Benchmark_UnSafe_LockUnlock(b *testing.B) { 28 | for i := 0; i < b.N; i++ { 29 | unsafeLock.Lock() 30 | unsafeLock.Unlock() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /os/gfile/gfile_z_example_sort_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gfile_test 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/gogf/gf/v2/os/gfile" 13 | ) 14 | 15 | func ExampleSortFiles() { 16 | files := []string{ 17 | "/aaa/bbb/ccc.txt", 18 | "/aaa/bbb/", 19 | "/aaa/", 20 | "/aaa", 21 | "/aaa/ccc/ddd.txt", 22 | "/bbb", 23 | "/0123", 24 | "/ddd", 25 | "/ccc", 26 | } 27 | sortOut := gfile.SortFiles(files) 28 | fmt.Println(sortOut) 29 | 30 | // Output: 31 | // [/0123 /aaa /aaa/ /aaa/bbb/ /aaa/bbb/ccc.txt /aaa/ccc/ddd.txt /bbb /ccc /ddd] 32 | } 33 | -------------------------------------------------------------------------------- /os/gproc/gproc_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" -benchmem 8 | 9 | package gproc_test 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/gogf/gf/v2/os/gproc" 15 | "github.com/gogf/gf/v2/test/gtest" 16 | ) 17 | 18 | func Test_ShellExec(t *testing.T) { 19 | gtest.C(t, func(t *gtest.T) { 20 | s, err := gproc.ShellExec(`echo 123`) 21 | t.AssertNil(err) 22 | t.Assert(s, "123\n") 23 | }) 24 | // error 25 | gtest.C(t, func(t *gtest.T) { 26 | _, err := gproc.ShellExec(`NoneExistCommandCall`) 27 | t.AssertNE(err, nil) 28 | }) 29 | } 30 | -------------------------------------------------------------------------------- /util/gvalid/gvalid_validator_rule_luhn.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gvalid 8 | 9 | // checkLuHn checks `value` with LUHN algorithm. 10 | // It's usually used for bank card number validation. 11 | func (v *Validator) checkLuHn(value string) bool { 12 | var ( 13 | sum = 0 14 | nDigits = len(value) 15 | parity = nDigits % 2 16 | ) 17 | for i := 0; i < nDigits; i++ { 18 | var digit = int(value[i] - 48) 19 | if i%2 == parity { 20 | digit *= 2 21 | if digit > 9 { 22 | digit -= 9 23 | } 24 | } 25 | sum += digit 26 | } 27 | return sum%10 == 0 28 | } 29 | -------------------------------------------------------------------------------- /os/gtime/gtime_time_wrapper.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gtime 8 | 9 | import ( 10 | "time" 11 | ) 12 | 13 | // wrapper is a wrapper for stdlib struct time.Time. 14 | // It's used for overwriting some functions of time.Time, for example: String. 15 | type wrapper struct { 16 | time.Time 17 | } 18 | 19 | // String overwrites the String function of time.Time. 20 | func (t wrapper) String() string { 21 | if t.IsZero() { 22 | return "" 23 | } 24 | if t.Year() == 0 { 25 | // Only time. 26 | return t.Format("15:04:05") 27 | } 28 | return t.Format("2006-01-02 15:04:05") 29 | } 30 | -------------------------------------------------------------------------------- /net/gsvc/gsvc_search.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsvc 8 | 9 | // Key formats and returns a string for prefix searching purpose. 10 | func (s *SearchInput) Key() string { 11 | keyPrefix := "" 12 | if s.Prefix != "" { 13 | keyPrefix += "/" + s.Prefix 14 | } 15 | if s.Deployment != "" { 16 | keyPrefix += "/" + s.Deployment 17 | if s.Namespace != "" { 18 | keyPrefix += "/" + s.Namespace 19 | if s.Name != "" { 20 | keyPrefix += "/" + s.Name 21 | if s.Version != "" { 22 | keyPrefix += "/" + s.Version 23 | } 24 | } 25 | } 26 | } 27 | return keyPrefix 28 | } 29 | -------------------------------------------------------------------------------- /encoding/ghash/ghash_jshash.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghash 8 | 9 | // JS implements the classic JS hash algorithm for 32 bits. 10 | func JS(str []byte) uint32 { 11 | var hash uint32 = 1315423911 12 | for i := 0; i < len(str); i++ { 13 | hash ^= (hash << 5) + uint32(str[i]) + (hash >> 2) 14 | } 15 | return hash 16 | } 17 | 18 | // JS64 implements the classic JS hash algorithm for 64 bits. 19 | func JS64(str []byte) uint64 { 20 | var hash uint64 = 1315423911 21 | for i := 0; i < len(str); i++ { 22 | hash ^= (hash << 5) + uint64(str[i]) + (hash >> 2) 23 | } 24 | return hash 25 | } 26 | -------------------------------------------------------------------------------- /util/gtag/gtag_z_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gtag_test 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/gogf/gf/v2/frame/g" 13 | "github.com/gogf/gf/v2/util/gmeta" 14 | "github.com/gogf/gf/v2/util/gtag" 15 | ) 16 | 17 | func ExampleSet() { 18 | type User struct { 19 | g.Meta `name:"User Struct" description:"{UserDescription}"` 20 | } 21 | gtag.Sets(g.MapStrStr{ 22 | `UserDescription`: `This is a demo struct named "User Struct"`, 23 | }) 24 | fmt.Println(gmeta.Get(User{}, `description`)) 25 | 26 | // Output: 27 | // This is a demo struct named "User Struct" 28 | } 29 | -------------------------------------------------------------------------------- /frame/gins/gins_httpclient.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gins 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/gogf/gf/v2/net/gclient" 13 | ) 14 | 15 | const ( 16 | frameCoreComponentNameHttpClient = "gf.core.component.httpclient" 17 | ) 18 | 19 | // HttpClient returns an instance of http client with specified name. 20 | func HttpClient(name ...interface{}) *gclient.Client { 21 | var instanceKey = fmt.Sprintf("%s.%v", frameCoreComponentNameHttpClient, name) 22 | return localInstances.GetOrSetFuncLock(instanceKey, func() interface{} { 23 | return gclient.New() 24 | }).(*gclient.Client) 25 | } 26 | -------------------------------------------------------------------------------- /util/gutil/gutil_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" -benchmem 8 | 9 | package gutil 10 | 11 | import ( 12 | "testing" 13 | ) 14 | 15 | var ( 16 | m1 = map[string]interface{}{ 17 | "k1": "v1", 18 | } 19 | m2 = map[string]interface{}{ 20 | "k2": "v2", 21 | } 22 | ) 23 | 24 | func Benchmark_TryCatch(b *testing.B) { 25 | for i := 0; i < b.N; i++ { 26 | TryCatch(func() { 27 | 28 | }, func(err error) { 29 | 30 | }) 31 | } 32 | } 33 | 34 | func Benchmark_MapMergeCopy(b *testing.B) { 35 | for i := 0; i < b.N; i++ { 36 | MapMergeCopy(m1, m2) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /database/gredis/gredis_subscription.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gredis 8 | 9 | import "fmt" 10 | 11 | // Subscription received after a successful subscription to channel. 12 | type Subscription struct { 13 | Kind string // Can be "subscribe", "unsubscribe", "psubscribe" or "punsubscribe". 14 | Channel string // Channel name we have subscribed to. 15 | Count int // Number of channels we are currently subscribed to. 16 | } 17 | 18 | // String converts current object to a readable string. 19 | func (m *Subscription) String() string { 20 | return fmt.Sprintf("%s: %s", m.Kind, m.Channel) 21 | } 22 | -------------------------------------------------------------------------------- /internal/utils/utils_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package utils_test 8 | 9 | import ( 10 | "regexp" 11 | "testing" 12 | 13 | "github.com/gogf/gf/v2/internal/utils" 14 | ) 15 | 16 | var ( 17 | replaceCharReg, _ = regexp.Compile(`[\-\.\_\s]+`) 18 | ) 19 | 20 | func Benchmark_RemoveSymbols(b *testing.B) { 21 | for i := 0; i < b.N; i++ { 22 | utils.RemoveSymbols(`-a-b._a c1!@#$%^&*()_+:";'.,'01`) 23 | } 24 | } 25 | 26 | func Benchmark_RegularReplaceChars(b *testing.B) { 27 | for i := 0; i < b.N; i++ { 28 | replaceCharReg.ReplaceAllString(`-a-b._a c1!@#$%^&*()_+:";'.,'01`, "") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /database/gdb/testdata/reservedwords_table_tpl.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE %s ( 2 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 3 | `key` varchar(45) DEFAULT NULL, 4 | `category_id` int(10) unsigned NOT NULL, 5 | `user_id` int(10) unsigned NOT NULL, 6 | `title` varchar(255) NOT NULL, 7 | `content` mediumtext NOT NULL, 8 | `sort` int(10) unsigned DEFAULT '0', 9 | `brief` varchar(255) DEFAULT NULL, 10 | `thumb` varchar(255) DEFAULT NULL, 11 | `tags` varchar(900) DEFAULT NULL, 12 | `referer` varchar(255) DEFAULT NULL, 13 | `status` smallint(5) unsigned DEFAULT '0', 14 | `view_count` int(10) unsigned DEFAULT '0', 15 | `zan_count` int(10) unsigned DEFAULT NULL, 16 | `cai_count` int(10) unsigned DEFAULT NULL, 17 | `created_at` datetime DEFAULT NULL, 18 | `updated_at` datetime DEFAULT NULL, 19 | PRIMARY KEY (`id`) 20 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /example/trace/http/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/gogf/gf/contrib/trace/jaeger/v2" 5 | "github.com/gogf/gf/v2/frame/g" 6 | "github.com/gogf/gf/v2/net/gtrace" 7 | "github.com/gogf/gf/v2/os/gctx" 8 | ) 9 | 10 | const ( 11 | ServiceName = "http-client" 12 | JaegerUdpEndpoint = "localhost:6831" 13 | ) 14 | 15 | func main() { 16 | var ctx = gctx.New() 17 | tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint) 18 | if err != nil { 19 | g.Log().Fatal(ctx, err) 20 | } 21 | defer tp.Shutdown(ctx) 22 | 23 | StartRequests() 24 | } 25 | 26 | func StartRequests() { 27 | ctx, span := gtrace.NewSpan(gctx.New(), "StartRequests") 28 | defer span.End() 29 | 30 | ctx = gtrace.SetBaggageValue(ctx, "name", "john") 31 | 32 | content := g.Client().GetContent(ctx, "http://127.0.0.1:8199/hello") 33 | g.Log().Print(ctx, content) 34 | } 35 | -------------------------------------------------------------------------------- /example/httpserver/swagger/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | "github.com/gogf/gf/v2/frame/g" 8 | "github.com/gogf/gf/v2/net/ghttp" 9 | ) 10 | 11 | type HelloReq struct { 12 | g.Meta `path:"/hello" method:"get" sort:"1"` 13 | Name string `v:"required" dc:"Your name"` 14 | } 15 | type HelloRes struct { 16 | Reply string `dc:"Reply content"` 17 | } 18 | 19 | type Hello struct{} 20 | 21 | func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error) { 22 | g.Log().Debugf(ctx, `receive say: %+v`, req) 23 | res = &HelloRes{ 24 | Reply: fmt.Sprintf(`Hi %s`, req.Name), 25 | } 26 | return 27 | } 28 | 29 | func main() { 30 | s := g.Server() 31 | s.Use(ghttp.MiddlewareHandlerResponse) 32 | s.Group("/", func(group *ghttp.RouterGroup) { 33 | group.Bind( 34 | new(Hello), 35 | ) 36 | }) 37 | s.Run() 38 | } 39 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_server_config_route.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp 8 | 9 | // SetRewrite sets rewrites for static URI for server. 10 | func (s *Server) SetRewrite(uri string, rewrite string) { 11 | s.config.Rewrites[uri] = rewrite 12 | } 13 | 14 | // SetRewriteMap sets the rewritten map for server. 15 | func (s *Server) SetRewriteMap(rewrites map[string]string) { 16 | for k, v := range rewrites { 17 | s.config.Rewrites[k] = v 18 | } 19 | } 20 | 21 | // SetRouteOverWrite sets the RouteOverWrite for server. 22 | func (s *Server) SetRouteOverWrite(enabled bool) { 23 | s.config.RouteOverWrite = enabled 24 | } 25 | -------------------------------------------------------------------------------- /text/gstr/gstr_contain.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gstr 8 | 9 | import "strings" 10 | 11 | // Contains reports whether `substr` is within `str`, case-sensitively. 12 | func Contains(str, substr string) bool { 13 | return strings.Contains(str, substr) 14 | } 15 | 16 | // ContainsI reports whether substr is within str, case-insensitively. 17 | func ContainsI(str, substr string) bool { 18 | return PosI(str, substr) != -1 19 | } 20 | 21 | // ContainsAny reports whether any Unicode code points in `chars` are within `s`. 22 | func ContainsAny(s, chars string) bool { 23 | return strings.ContainsAny(s, chars) 24 | } 25 | -------------------------------------------------------------------------------- /os/gfile/gfile_z_example_search_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gfile_test 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/gogf/gf/v2/os/gfile" 13 | ) 14 | 15 | func ExampleSearch() { 16 | // init 17 | var ( 18 | fileName = "gflie_example.txt" 19 | tempDir = gfile.Temp("gfile_example_search") 20 | tempFile = gfile.Join(tempDir, fileName) 21 | ) 22 | 23 | // write contents 24 | gfile.PutContents(tempFile, "goframe example content") 25 | 26 | // search file 27 | realPath, _ := gfile.Search(fileName, tempDir) 28 | fmt.Println(gfile.Basename(realPath)) 29 | 30 | // Output: 31 | // gflie_example.txt 32 | } 33 | -------------------------------------------------------------------------------- /protocol/goai/goai_header.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/internal/json" 11 | ) 12 | 13 | // Header is specified by OpenAPI/Swagger 3.0 standard. 14 | // See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#headerObject 15 | type Header struct { 16 | Parameter 17 | } 18 | 19 | type Headers map[string]HeaderRef 20 | 21 | type HeaderRef struct { 22 | Ref string 23 | Value *Header 24 | } 25 | 26 | func (r HeaderRef) MarshalJSON() ([]byte, error) { 27 | if r.Ref != "" { 28 | return formatRefToBytes(r.Ref), nil 29 | } 30 | return json.Marshal(r.Value) 31 | } 32 | -------------------------------------------------------------------------------- /os/gfile/gfile_z_example_time_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gfile_test 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/gogf/gf/v2/os/gfile" 13 | ) 14 | 15 | func ExampleMTime() { 16 | t := gfile.MTime(gfile.Temp()) 17 | fmt.Println(t) 18 | 19 | // May Output: 20 | // 2021-11-02 15:18:43.901141 +0800 CST 21 | } 22 | 23 | func ExampleMTimestamp() { 24 | t := gfile.MTimestamp(gfile.Temp()) 25 | fmt.Println(t) 26 | 27 | // May Output: 28 | // 1635838398 29 | } 30 | 31 | func ExampleMTimestampMilli() { 32 | t := gfile.MTimestampMilli(gfile.Temp()) 33 | fmt.Println(t) 34 | 35 | // May Output: 36 | // 1635838529330 37 | } 38 | -------------------------------------------------------------------------------- /test/gtest/gtest_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gtest_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/test/gtest" 13 | ) 14 | 15 | func TestC(t *testing.T) { 16 | gtest.C(t, func(t *gtest.T) { 17 | t.Assert(1, 1) 18 | t.AssertNE(1, 0) 19 | t.AssertEQ(float32(123.456), float32(123.456)) 20 | t.AssertEQ(float64(123.456), float64(123.456)) 21 | }) 22 | } 23 | 24 | func TestCase(t *testing.T) { 25 | gtest.C(t, func(t *gtest.T) { 26 | t.Assert(1, 1) 27 | t.AssertNE(1, 0) 28 | t.AssertEQ(float32(123.456), float32(123.456)) 29 | t.AssertEQ(float64(123.456), float64(123.456)) 30 | }) 31 | } 32 | -------------------------------------------------------------------------------- /net/gclient/gclient_websocket.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gclient 8 | 9 | import ( 10 | "net/http" 11 | "time" 12 | 13 | "github.com/gorilla/websocket" 14 | ) 15 | 16 | // WebSocketClient wraps the underlying websocket client connection 17 | // and provides convenient functions. 18 | type WebSocketClient struct { 19 | *websocket.Dialer 20 | } 21 | 22 | // NewWebSocket creates and returns a new WebSocketClient object. 23 | func NewWebSocket() *WebSocketClient { 24 | return &WebSocketClient{ 25 | &websocket.Dialer{ 26 | Proxy: http.ProxyFromEnvironment, 27 | HandshakeTimeout: 45 * time.Second, 28 | }, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /os/gctx/gctx_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gctx_test 8 | 9 | import ( 10 | "context" 11 | "testing" 12 | 13 | "github.com/gogf/gf/v2/os/gctx" 14 | "github.com/gogf/gf/v2/test/gtest" 15 | ) 16 | 17 | func Test_New(t *testing.T) { 18 | gtest.C(t, func(t *gtest.T) { 19 | ctx := gctx.New() 20 | t.AssertNE(ctx, nil) 21 | t.AssertNE(gctx.CtxId(ctx), "") 22 | }) 23 | } 24 | 25 | func Test_WithCtx(t *testing.T) { 26 | gtest.C(t, func(t *gtest.T) { 27 | ctx := context.WithValue(context.TODO(), "TEST", 1) 28 | ctx = gctx.WithCtx(ctx) 29 | t.AssertNE(gctx.CtxId(ctx), "") 30 | t.Assert(ctx.Value("TEST"), 1) 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /os/gtimer/gtimer_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gtimer 8 | 9 | import ( 10 | "context" 11 | "testing" 12 | "time" 13 | ) 14 | 15 | var ( 16 | ctx = context.TODO() 17 | timer = New() 18 | ) 19 | 20 | func Benchmark_Add(b *testing.B) { 21 | for i := 0; i < b.N; i++ { 22 | timer.Add(ctx, time.Hour, func(ctx context.Context) { 23 | 24 | }) 25 | } 26 | } 27 | 28 | func Benchmark_PriorityQueue_Pop(b *testing.B) { 29 | for i := 0; i < b.N; i++ { 30 | timer.queue.Pop() 31 | } 32 | } 33 | 34 | func Benchmark_StartStop(b *testing.B) { 35 | for i := 0; i < b.N; i++ { 36 | timer.Start() 37 | timer.Stop() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /errors/gerror/gerror_stack.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gerror 8 | 9 | import "runtime" 10 | 11 | // stack represents a stack of program counters. 12 | type stack []uintptr 13 | 14 | const ( 15 | // maxStackDepth marks the max stack depth for error back traces. 16 | maxStackDepth = 32 17 | ) 18 | 19 | // callers returns the stack callers. 20 | // Note that it here just retrieves the caller memory address array not the caller information. 21 | func callers(skip ...int) stack { 22 | var ( 23 | pcs [maxStackDepth]uintptr 24 | n = 3 25 | ) 26 | if len(skip) > 0 { 27 | n += skip[0] 28 | } 29 | return pcs[:runtime.Callers(n, pcs[:])] 30 | } 31 | -------------------------------------------------------------------------------- /net/gipv6/gipv6.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gipv6 provides useful API for IPv6 address handling. 8 | package gipv6 9 | 10 | import "github.com/gogf/gf/v2/text/gregex" 11 | 12 | // Validate checks whether given `ip` a valid IPv6 address. 13 | func Validate(ip string) bool { 14 | return gregex.IsMatchString(`^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$|^:((:[\da-fA-F]{1,4}){1,6}|:)$|^[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,5}|:)$|^([\da-fA-F]{1,4}:){2}((:[\da-fA-F]{1,4}){1,4}|:)$|^([\da-fA-F]{1,4}:){3}((:[\da-fA-F]{1,4}){1,3}|:)$|^([\da-fA-F]{1,4}:){4}((:[\da-fA-F]{1,4}){1,2}|:)$|^([\da-fA-F]{1,4}:){5}:([\da-fA-F]{1,4})?$|^([\da-fA-F]{1,4}:){6}:$`, ip) 15 | } 16 | -------------------------------------------------------------------------------- /frame/gins/gins_z_unit_httpclient_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gins_test 8 | 9 | import ( 10 | "fmt" 11 | "testing" 12 | 13 | "github.com/gogf/gf/v2/frame/gins" 14 | "github.com/gogf/gf/v2/test/gtest" 15 | ) 16 | 17 | func Test_Client(t *testing.T) { 18 | gtest.C(t, func(t *gtest.T) { 19 | var ( 20 | c = gins.HttpClient() 21 | c1 = gins.HttpClient("c1") 22 | c2 = gins.HttpClient("c2") 23 | ) 24 | c.SetAgent("test1") 25 | c.SetAgent("test2") 26 | t.AssertNE(fmt.Sprintf(`%p`, c), fmt.Sprintf(`%p`, c1)) 27 | t.AssertNE(fmt.Sprintf(`%p`, c), fmt.Sprintf(`%p`, c2)) 28 | t.AssertNE(fmt.Sprintf(`%p`, c1), fmt.Sprintf(`%p`, c2)) 29 | }) 30 | } 31 | -------------------------------------------------------------------------------- /util/gvalid/gvalid_z_unit_feature_ci_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gvalid_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/frame/g" 13 | "github.com/gogf/gf/v2/test/gtest" 14 | ) 15 | 16 | func Test_CI(t *testing.T) { 17 | gtest.C(t, func(t *gtest.T) { 18 | err := g.Validator().Data("id").Rules("in:Id,Name").Run(ctx) 19 | t.AssertNE(err, nil) 20 | }) 21 | gtest.C(t, func(t *gtest.T) { 22 | err := g.Validator().Data("id").Rules("ci|in:Id,Name").Run(ctx) 23 | t.AssertNil(err) 24 | }) 25 | gtest.C(t, func(t *gtest.T) { 26 | err := g.Validator().Ci().Rules("in:Id,Name").Data("id").Run(ctx) 27 | t.AssertNil(err) 28 | }) 29 | } 30 | -------------------------------------------------------------------------------- /util/guid/guid_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" 8 | 9 | package guid_test 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/gogf/gf/v2/container/gset" 15 | "github.com/gogf/gf/v2/test/gtest" 16 | "github.com/gogf/gf/v2/util/guid" 17 | ) 18 | 19 | func Test_S(t *testing.T) { 20 | gtest.C(t, func(t *gtest.T) { 21 | set := gset.NewStrSet() 22 | for i := 0; i < 1000000; i++ { 23 | s := guid.S() 24 | t.Assert(set.AddIfNotExist(s), true) 25 | t.Assert(len(s), 32) 26 | } 27 | }) 28 | } 29 | 30 | func Test_S_Data(t *testing.T) { 31 | gtest.C(t, func(t *gtest.T) { 32 | t.Assert(len(guid.S([]byte("123"))), 32) 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /os/gres/gres_instance.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gres 8 | 9 | import "github.com/gogf/gf/v2/container/gmap" 10 | 11 | const ( 12 | // DefaultName default group name for instance usage. 13 | DefaultName = "default" 14 | ) 15 | 16 | var ( 17 | // Instances map. 18 | instances = gmap.NewStrAnyMap(true) 19 | ) 20 | 21 | // Instance returns an instance of Resource. 22 | // The parameter `name` is the name for the instance. 23 | func Instance(name ...string) *Resource { 24 | key := DefaultName 25 | if len(name) > 0 && name[0] != "" { 26 | key = name[0] 27 | } 28 | return instances.GetOrSetFuncLock(key, func() interface{} { 29 | return New() 30 | }).(*Resource) 31 | } 32 | -------------------------------------------------------------------------------- /database/gdb/gdb_schema.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gdb 8 | 9 | // Schema is a schema object from which it can then create a Model. 10 | type Schema struct { 11 | DB 12 | } 13 | 14 | // Schema creates and returns a schema. 15 | func (c *Core) Schema(schema string) *Schema { 16 | // Do not change the schema of the original db, 17 | // it here creates a new db and changes its schema. 18 | db, err := NewByGroup(c.GetGroup()) 19 | if err != nil { 20 | panic(err) 21 | } 22 | core := db.GetCore() 23 | // Different schema share some same objects. 24 | core.logger = c.logger 25 | core.cache = c.cache 26 | core.schema = schema 27 | return &Schema{ 28 | DB: db, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /frame/gins/testdata/config/config.toml: -------------------------------------------------------------------------------- 1 | # 模板引擎目录 2 | viewpath = "/home/www/templates/" 3 | test = "v=1" 4 | # MySQL数据库配置 5 | [database] 6 | [[database.default]] 7 | host = "127.0.0.1" 8 | port = "3306" 9 | user = "root" 10 | pass = "" 11 | name = "test" 12 | type = "mysql" 13 | role = "master" 14 | charset = "utf8" 15 | priority = "1" 16 | [[database.default]] 17 | host = "127.0.0.1" 18 | port = "3306" 19 | user = "root" 20 | pass = "8692651" 21 | name = "test" 22 | type = "mysql" 23 | role = "master" 24 | charset = "utf8" 25 | priority = "1" 26 | # Redis数据库配置 27 | [redis] 28 | [redis.disk] 29 | address = "127.0.0.1:6379" 30 | db = 1 31 | [redis.cache] 32 | address = "127.0.0.1:6379" 33 | db = 1 -------------------------------------------------------------------------------- /frame/gins/testdata/database/config.toml: -------------------------------------------------------------------------------- 1 | # 模板引擎目录 2 | viewpath = "/home/www/templates/" 3 | test = "v=2" 4 | # MySQL数据库配置 5 | [database] 6 | [[database.default]] 7 | host = "127.0.0.1" 8 | port = "3306" 9 | user = "root" 10 | pass = "12345678" 11 | name = "test" 12 | type = "mysql" 13 | role = "master" 14 | weight = "1" 15 | charset = "utf8" 16 | [[database.test]] 17 | host = "127.0.0.1" 18 | port = "3306" 19 | user = "root" 20 | pass = "12345678" 21 | name = "test" 22 | type = "mysql" 23 | role = "master" 24 | weight = "1" 25 | charset = "utf8" 26 | # Redis数据库配置 27 | [redis] 28 | [redis.default] 29 | address = "127.0.0.1:6379" 30 | db = 1 31 | [redis.cache] 32 | address = "127.0.0.1:6379" 33 | db = 1 -------------------------------------------------------------------------------- /util/guid/guid_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" 8 | 9 | package guid_test 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/gogf/gf/v2/util/guid" 15 | ) 16 | 17 | func Benchmark_S(b *testing.B) { 18 | b.RunParallel(func(pb *testing.PB) { 19 | for pb.Next() { 20 | guid.S() 21 | } 22 | }) 23 | } 24 | 25 | func Benchmark_S_Data_1(b *testing.B) { 26 | b.RunParallel(func(pb *testing.PB) { 27 | for pb.Next() { 28 | guid.S([]byte("123")) 29 | } 30 | }) 31 | } 32 | 33 | func Benchmark_S_Data_2(b *testing.B) { 34 | b.RunParallel(func(pb *testing.PB) { 35 | for pb.Next() { 36 | guid.S([]byte("123"), []byte("456")) 37 | } 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /container/gvar/gvar_struct.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gvar 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/util/gconv" 11 | ) 12 | 13 | // Struct maps value of `v` to `pointer`. 14 | // The parameter `pointer` should be a pointer to a struct instance. 15 | // The parameter `mapping` is used to specify the key-to-attribute mapping rules. 16 | func (v *Var) Struct(pointer interface{}, mapping ...map[string]string) error { 17 | return gconv.Struct(v.Val(), pointer, mapping...) 18 | } 19 | 20 | // Structs converts and returns `v` as given struct slice. 21 | func (v *Var) Structs(pointer interface{}, mapping ...map[string]string) error { 22 | return gconv.Structs(v.Val(), pointer, mapping...) 23 | } 24 | -------------------------------------------------------------------------------- /os/glog/glog_instance.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package glog 8 | 9 | import "github.com/gogf/gf/v2/container/gmap" 10 | 11 | const ( 12 | // DefaultName is the default group name for instance usage. 13 | DefaultName = "default" 14 | ) 15 | 16 | var ( 17 | // Instances map. 18 | instances = gmap.NewStrAnyMap(true) 19 | ) 20 | 21 | // Instance returns an instance of Logger with default settings. 22 | // The parameter `name` is the name for the instance. 23 | func Instance(name ...string) *Logger { 24 | key := DefaultName 25 | if len(name) > 0 && name[0] != "" { 26 | key = name[0] 27 | } 28 | return instances.GetOrSetFuncLock(key, func() interface{} { 29 | return New() 30 | }).(*Logger) 31 | } 32 | -------------------------------------------------------------------------------- /os/gview/gview_instance.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gview 8 | 9 | import "github.com/gogf/gf/v2/container/gmap" 10 | 11 | const ( 12 | // DefaultName is the default group name for instance usage. 13 | DefaultName = "default" 14 | ) 15 | 16 | var ( 17 | // Instances map. 18 | instances = gmap.NewStrAnyMap(true) 19 | ) 20 | 21 | // Instance returns an instance of View with default settings. 22 | // The parameter `name` is the name for the instance. 23 | func Instance(name ...string) *View { 24 | key := DefaultName 25 | if len(name) > 0 && name[0] != "" { 26 | key = name[0] 27 | } 28 | return instances.GetOrSetFuncLock(key, func() interface{} { 29 | return New() 30 | }).(*View) 31 | } 32 | -------------------------------------------------------------------------------- /encoding/ghash/ghash_bkdr.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghash 8 | 9 | // BKDR implements the classic BKDR hash algorithm for 32 bits. 10 | func BKDR(str []byte) uint32 { 11 | var ( 12 | seed uint32 = 131 // 31 131 1313 13131 131313 etc.. 13 | hash uint32 = 0 14 | ) 15 | for i := 0; i < len(str); i++ { 16 | hash = hash*seed + uint32(str[i]) 17 | } 18 | return hash 19 | } 20 | 21 | // BKDR64 implements the classic BKDR hash algorithm for 64 bits. 22 | func BKDR64(str []byte) uint64 { 23 | var ( 24 | seed uint64 = 131 // 31 131 1313 13131 131313 etc.. 25 | hash uint64 = 0 26 | ) 27 | for i := 0; i < len(str); i++ { 28 | hash = hash*seed + uint64(str[i]) 29 | } 30 | return hash 31 | } 32 | -------------------------------------------------------------------------------- /encoding/ghash/ghash_rs.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghash 8 | 9 | // RS implements the classic RS hash algorithm for 32 bits. 10 | func RS(str []byte) uint32 { 11 | var ( 12 | b uint32 = 378551 13 | a uint32 = 63689 14 | hash uint32 = 0 15 | ) 16 | for i := 0; i < len(str); i++ { 17 | hash = hash*a + uint32(str[i]) 18 | a *= b 19 | } 20 | return hash 21 | } 22 | 23 | // RS64 implements the classic RS hash algorithm for 64 bits. 24 | func RS64(str []byte) uint64 { 25 | var ( 26 | b uint64 = 378551 27 | a uint64 = 63689 28 | hash uint64 = 0 29 | ) 30 | for i := 0; i < len(str); i++ { 31 | hash = hash*a + uint64(str[i]) 32 | a *= b 33 | } 34 | return hash 35 | } 36 | -------------------------------------------------------------------------------- /os/gsession/gsession.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gsession implements manager and storage features for sessions. 8 | package gsession 9 | 10 | import ( 11 | "github.com/gogf/gf/v2/errors/gcode" 12 | "github.com/gogf/gf/v2/errors/gerror" 13 | "github.com/gogf/gf/v2/util/guid" 14 | ) 15 | 16 | var ( 17 | // ErrorDisabled is used for marking certain interface function not used. 18 | ErrorDisabled = gerror.NewOption(gerror.Option{ 19 | Text: "this feature is disabled in this storage", 20 | Code: gcode.CodeNotSupported, 21 | }) 22 | ) 23 | 24 | // NewSessionId creates and returns a new and unique session id string, 25 | // which is in 36 bytes. 26 | func NewSessionId() string { 27 | return guid.S() 28 | } 29 | -------------------------------------------------------------------------------- /encoding/ghash/ghash_sdbm.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghash 8 | 9 | // SDBM implements the classic SDBM hash algorithm for 32 bits. 10 | func SDBM(str []byte) uint32 { 11 | var hash uint32 = 0 12 | for i := 0; i < len(str); i++ { 13 | // equivalent to: hash = 65599*hash + uint32(str[i]); 14 | hash = uint32(str[i]) + (hash << 6) + (hash << 16) - hash 15 | } 16 | return hash 17 | } 18 | 19 | // SDBM64 implements the classic SDBM hash algorithm for 64 bits. 20 | func SDBM64(str []byte) uint64 { 21 | var hash uint64 = 0 22 | for i := 0; i < len(str); i++ { 23 | // equivalent to: hash = 65599*hash + uint32(str[i]) 24 | hash = uint64(str[i]) + (hash << 6) + (hash << 16) - hash 25 | } 26 | return hash 27 | } 28 | -------------------------------------------------------------------------------- /os/gres/testdata/example/boot/data.go: -------------------------------------------------------------------------------- 1 | package boot 2 | 3 | import "github.com/gogf/gf/v2/os/gres" 4 | 5 | func init() { 6 | if err := gres.Add("1f8b08000000000002ff0af066661161e060606048cea809604002420c9c0cc9f9796999e9fa104aaf243f37273484958191cbbb3e8e2bba38b5a82cb528964b414141c13125a528b5b818c4b45550b2b2b0b0b050024b04831505e5e79780240a4a9372329395b8b8a2cb3253cb619a5d52d3124b734adc327352418a32f352522bf44a0a7294a0b23999b99925a945c520b315a29554aa957414946a9562b9b8b8b802bcd939b81c64d7b63330308030c23fad68fe6183fb07ec072feffa389066642508cdd6e9a89a05193819208ed787382fa3041a16973cebe33c527372f21541a6859dd19acb06b68c905320a611e1940c2cf152929a5b90935892aa0f0f2bb041a2de50b728a854ebe525e6a6d6821d75255b6e263f0303033f5e477120998bc7598c4c22cc8804831cf42087c1c09246108927f9201b842d7860c1cee070016e1092ab109a4131851cea8228aee06564c0136fc43b221a6e0e564780e2083994518362062303be18c3e70a0e14577c403208c91dac6c1007b3314c666460d06702f100010000ffffc7c852f1d8030000"); err != nil { 7 | panic(err) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/trace/http/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/gogf/gf/contrib/trace/jaeger/v2" 5 | "github.com/gogf/gf/v2/frame/g" 6 | "github.com/gogf/gf/v2/net/ghttp" 7 | "github.com/gogf/gf/v2/net/gtrace" 8 | "github.com/gogf/gf/v2/os/gctx" 9 | ) 10 | 11 | const ( 12 | ServiceName = "http-server" 13 | JaegerUdpEndpoint = "localhost:6831" 14 | ) 15 | 16 | func main() { 17 | var ctx = gctx.New() 18 | tp, err := jaeger.Init(ServiceName, JaegerUdpEndpoint) 19 | if err != nil { 20 | g.Log().Fatal(ctx, err) 21 | } 22 | defer tp.Shutdown(ctx) 23 | 24 | s := g.Server() 25 | s.Group("/", func(group *ghttp.RouterGroup) { 26 | group.GET("/hello", HelloHandler) 27 | }) 28 | s.SetPort(8199) 29 | s.Run() 30 | } 31 | 32 | func HelloHandler(r *ghttp.Request) { 33 | ctx, span := gtrace.NewSpan(r.Context(), "HelloHandler") 34 | defer span.End() 35 | 36 | value := gtrace.GetBaggageVar(ctx, "name").String() 37 | 38 | r.Response.Write("hello:", value) 39 | } 40 | -------------------------------------------------------------------------------- /os/gstructs/gstructs_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gstructs_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/os/gstructs" 13 | ) 14 | 15 | type User struct { 16 | Id int 17 | Name string `params:"name"` 18 | Pass string `my-tag1:"pass1" my-tag2:"pass2" params:"pass"` 19 | } 20 | 21 | var ( 22 | user = new(User) 23 | userNilPointer *User 24 | ) 25 | 26 | func Benchmark_TagFields(b *testing.B) { 27 | for i := 0; i < b.N; i++ { 28 | gstructs.TagFields(user, []string{"params", "my-tag1"}) 29 | } 30 | } 31 | 32 | func Benchmark_TagFields_NilPointer(b *testing.B) { 33 | for i := 0; i < b.N; i++ { 34 | gstructs.TagFields(&userNilPointer, []string{"params", "my-tag1"}) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /debug/gdebug/gdebug_grid.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gdebug 8 | 9 | import ( 10 | "regexp" 11 | "runtime" 12 | "strconv" 13 | ) 14 | 15 | var ( 16 | // gridRegex is the regular expression object for parsing goroutine id from stack information. 17 | gridRegex = regexp.MustCompile(`^\w+\s+(\d+)\s+`) 18 | ) 19 | 20 | // GoroutineId retrieves and returns the current goroutine id from stack information. 21 | // Be very aware that, it is with low performance as it uses runtime.Stack function. 22 | // It is commonly used for debugging purpose. 23 | func GoroutineId() int { 24 | buf := make([]byte, 26) 25 | runtime.Stack(buf, false) 26 | match := gridRegex.FindSubmatch(buf) 27 | id, _ := strconv.Atoi(string(match[1])) 28 | return id 29 | } 30 | -------------------------------------------------------------------------------- /os/gtime/gtime_z_unit_feature_sql_test.go: -------------------------------------------------------------------------------- 1 | package gtime_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/gogf/gf/v2/os/gtime" 7 | "github.com/gogf/gf/v2/test/gtest" 8 | ) 9 | 10 | func TestTime_Scan(t1 *testing.T) { 11 | gtest.C(t1, func(t *gtest.T) { 12 | tt := gtime.Time{} 13 | // test string 14 | s := gtime.Now().String() 15 | t.Assert(tt.Scan(s), nil) 16 | t.Assert(tt.String(), s) 17 | // test nano 18 | n := gtime.TimestampNano() 19 | t.Assert(tt.Scan(n), nil) 20 | t.Assert(tt.TimestampNano(), n) 21 | // test nil 22 | none := (*gtime.Time)(nil) 23 | t.Assert(none.Scan(nil), nil) 24 | t.Assert(none, nil) 25 | }) 26 | 27 | } 28 | 29 | func TestTime_Value(t1 *testing.T) { 30 | gtest.C(t1, func(t *gtest.T) { 31 | tt := gtime.Now() 32 | s, err := tt.Value() 33 | t.AssertNil(err) 34 | t.Assert(s, tt.Time) 35 | // test nil 36 | none := (*gtime.Time)(nil) 37 | s, err = none.Value() 38 | t.AssertNil(err) 39 | t.Assert(s, nil) 40 | 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /text/gstr/gstr_array.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gstr 8 | 9 | // SearchArray searches string `s` in string slice `a` case-sensitively, 10 | // returns its index in `a`. 11 | // If `s` is not found in `a`, it returns -1. 12 | func SearchArray(a []string, s string) int { 13 | for i, v := range a { 14 | if s == v { 15 | return i 16 | } 17 | } 18 | return NotFoundIndex 19 | } 20 | 21 | // InArray checks whether string `s` in slice `a`. 22 | func InArray(a []string, s string) bool { 23 | return SearchArray(a, s) != NotFoundIndex 24 | } 25 | 26 | // PrefixArray adds `prefix` string for each item of `array`. 27 | func PrefixArray(array []string, prefix string) { 28 | for k, v := range array { 29 | array[k] = prefix + v 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /crypto/gcrc32/gcrc32_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" 8 | 9 | package gcrc32_test 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/gogf/gf/v2/crypto/gcrc32" 15 | "github.com/gogf/gf/v2/crypto/gmd5" 16 | "github.com/gogf/gf/v2/test/gtest" 17 | ) 18 | 19 | func TestEncrypt(t *testing.T) { 20 | gtest.C(t, func(t *gtest.T) { 21 | s := "pibigstar" 22 | result := 693191136 23 | encrypt1 := gcrc32.Encrypt(s) 24 | encrypt2 := gcrc32.Encrypt([]byte(s)) 25 | t.AssertEQ(int(encrypt1), result) 26 | t.AssertEQ(int(encrypt2), result) 27 | 28 | strmd5, _ := gmd5.Encrypt(s) 29 | test1 := gcrc32.Encrypt(strmd5) 30 | test2 := gcrc32.Encrypt([]byte(strmd5)) 31 | t.AssertEQ(test2, test1) 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /protocol/goai/goai_server.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | // Server is specified by OpenAPI/Swagger standard version 3.0. 10 | type Server struct { 11 | URL string `json:"url"` 12 | Description string `json:"description,omitempty"` 13 | Variables map[string]*ServerVariable `json:"variables,omitempty"` 14 | } 15 | 16 | // ServerVariable is specified by OpenAPI/Swagger standard version 3.0. 17 | type ServerVariable struct { 18 | Enum []string `json:"enum,omitempty"` 19 | Default string `json:"default,omitempty"` 20 | Description string `json:"description,omitempty"` 21 | } 22 | 23 | // Servers is specified by OpenAPI/Swagger standard version 3.0. 24 | type Servers []Server 25 | -------------------------------------------------------------------------------- /i18n/gi18n/gi18n_instance.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gi18n 8 | 9 | import "github.com/gogf/gf/v2/container/gmap" 10 | 11 | const ( 12 | // DefaultName is the default group name for instance usage. 13 | DefaultName = "default" 14 | ) 15 | 16 | var ( 17 | // instances is the instances map for management 18 | // for multiple i18n instance by name. 19 | instances = gmap.NewStrAnyMap(true) 20 | ) 21 | 22 | // Instance returns an instance of Resource. 23 | // The parameter `name` is the name for the instance. 24 | func Instance(name ...string) *Manager { 25 | key := DefaultName 26 | if len(name) > 0 && name[0] != "" { 27 | key = name[0] 28 | } 29 | return instances.GetOrSetFuncLock(key, func() interface{} { 30 | return New() 31 | }).(*Manager) 32 | } 33 | -------------------------------------------------------------------------------- /net/gtrace/internal/provider/provider_idgenerator.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package provider 8 | 9 | import ( 10 | "context" 11 | 12 | "github.com/gogf/gf/v2/internal/tracing" 13 | "go.opentelemetry.io/otel/trace" 14 | ) 15 | 16 | type IDGenerator struct{} 17 | 18 | func NewIDGenerator() *IDGenerator { 19 | return &IDGenerator{} 20 | } 21 | 22 | // NewIDs creates and returns a new trace and span ID. 23 | func (id *IDGenerator) NewIDs(ctx context.Context) (traceID trace.TraceID, spanID trace.SpanID) { 24 | return tracing.NewIDs() 25 | } 26 | 27 | // NewSpanID returns an ID for a new span in the trace with traceID. 28 | func (id *IDGenerator) NewSpanID(ctx context.Context, traceID trace.TraceID) (spanID trace.SpanID) { 29 | return tracing.NewSpanID() 30 | } 31 | -------------------------------------------------------------------------------- /container/gpool/gpool_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" 8 | 9 | package gpool_test 10 | 11 | import ( 12 | "sync" 13 | "testing" 14 | "time" 15 | 16 | "github.com/gogf/gf/v2/container/gpool" 17 | ) 18 | 19 | var pool = gpool.New(time.Hour, nil) 20 | var syncp = sync.Pool{} 21 | 22 | func BenchmarkGPoolPut(b *testing.B) { 23 | for i := 0; i < b.N; i++ { 24 | pool.Put(i) 25 | } 26 | } 27 | 28 | func BenchmarkGPoolGet(b *testing.B) { 29 | for i := 0; i < b.N; i++ { 30 | pool.Get() 31 | } 32 | } 33 | 34 | func BenchmarkSyncPoolPut(b *testing.B) { 35 | for i := 0; i < b.N; i++ { 36 | syncp.Put(i) 37 | } 38 | } 39 | 40 | func BenchmarkSyncPoolGet(b *testing.B) { 41 | for i := 0; i < b.N; i++ { 42 | syncp.Get() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_server_plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp 8 | 9 | // Plugin is the interface for server plugin. 10 | type Plugin interface { 11 | Name() string // Name returns the name of the plugin. 12 | Author() string // Author returns the author of the plugin. 13 | Version() string // Version returns the version of the plugin, like "v1.0.0". 14 | Description() string // Description returns the description of the plugin. 15 | Install(s *Server) error // Install installs the plugin before the server starts. 16 | Remove() error // Remove removes the plugin. 17 | } 18 | 19 | // Plugin adds plugin to the server. 20 | func (s *Server) Plugin(plugin ...Plugin) { 21 | s.plugins = append(s.plugins, plugin...) 22 | } 23 | -------------------------------------------------------------------------------- /os/gcmd/gcmd_scan.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | // 7 | 8 | package gcmd 9 | 10 | import ( 11 | "bufio" 12 | "fmt" 13 | "os" 14 | 15 | "github.com/gogf/gf/v2/text/gstr" 16 | ) 17 | 18 | // Scan prints `info` to stdout, reads and returns user input, which stops by '\n'. 19 | func Scan(info ...interface{}) string { 20 | fmt.Print(info...) 21 | return readline() 22 | } 23 | 24 | // Scanf prints `info` to stdout with `format`, reads and returns user input, which stops by '\n'. 25 | func Scanf(format string, info ...interface{}) string { 26 | fmt.Printf(format, info...) 27 | return readline() 28 | } 29 | 30 | func readline() string { 31 | var s string 32 | reader := bufio.NewReader(os.Stdin) 33 | s, _ = reader.ReadString('\n') 34 | s = gstr.Trim(s) 35 | return s 36 | } 37 | -------------------------------------------------------------------------------- /protocol/goai/goai_example.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/internal/json" 11 | ) 12 | 13 | // Example is specified by OpenAPI/Swagger 3.0 standard. 14 | type Example struct { 15 | Summary string `json:"summary,omitempty"` 16 | Description string `json:"description,omitempty"` 17 | Value interface{} `json:"value,omitempty"` 18 | ExternalValue string `json:"externalValue,omitempty"` 19 | } 20 | 21 | type Examples map[string]*ExampleRef 22 | 23 | type ExampleRef struct { 24 | Ref string 25 | Value *Example 26 | } 27 | 28 | func (r ExampleRef) MarshalJSON() ([]byte, error) { 29 | if r.Ref != "" { 30 | return formatRefToBytes(r.Ref), nil 31 | } 32 | return json.Marshal(r.Value) 33 | } 34 | -------------------------------------------------------------------------------- /os/gproc/gproc_must.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gproc 8 | 9 | import ( 10 | "io" 11 | ) 12 | 13 | // MustShell performs as Shell, but it panics if any error occurs. 14 | func MustShell(cmd string, out io.Writer, in io.Reader) { 15 | if err := Shell(cmd, out, in); err != nil { 16 | panic(err) 17 | } 18 | } 19 | 20 | // MustShellRun performs as ShellRun, but it panics if any error occurs. 21 | func MustShellRun(cmd string) { 22 | if err := ShellRun(cmd); err != nil { 23 | panic(err) 24 | } 25 | } 26 | 27 | // MustShellExec performs as ShellExec, but it panics if any error occurs. 28 | func MustShellExec(cmd string, environment ...[]string) string { 29 | result, err := ShellExec(cmd, environment...) 30 | if err != nil { 31 | panic(err) 32 | } 33 | return result 34 | } 35 | -------------------------------------------------------------------------------- /util/gconv/gconv_unsafe.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gconv 8 | 9 | import "unsafe" 10 | 11 | // UnsafeStrToBytes converts string to []byte without memory copy. 12 | // Note that, if you completely sure you will never use `s` variable in the feature, 13 | // you can use this unsafe function to implement type conversion in high performance. 14 | func UnsafeStrToBytes(s string) []byte { 15 | return *(*[]byte)(unsafe.Pointer(&s)) 16 | } 17 | 18 | // UnsafeBytesToStr converts []byte to string without memory copy. 19 | // Note that, if you completely sure you will never use `b` variable in the feature, 20 | // you can use this unsafe function to implement type conversion in high performance. 21 | func UnsafeBytesToStr(b []byte) string { 22 | return *(*string)(unsafe.Pointer(&b)) 23 | } 24 | -------------------------------------------------------------------------------- /database/gdb/gdb_model_transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gdb 8 | 9 | import ( 10 | "context" 11 | ) 12 | 13 | // Transaction wraps the transaction logic using function `f`. 14 | // It rollbacks the transaction and returns the error from function `f` if 15 | // it returns non-nil error. It commits the transaction and returns nil if 16 | // function `f` returns nil. 17 | // 18 | // Note that, you should not Commit or Rollback the transaction in function `f` 19 | // as it is automatically handled by this function. 20 | func (m *Model) Transaction(ctx context.Context, f func(ctx context.Context, tx *TX) error) (err error) { 21 | if ctx == nil { 22 | ctx = m.GetCtx() 23 | } 24 | if m.tx != nil { 25 | return m.tx.Transaction(ctx, f) 26 | } 27 | return m.db.Transaction(ctx, f) 28 | } 29 | -------------------------------------------------------------------------------- /encoding/ghash/ghash_ap.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghash 8 | 9 | // AP implements the classic AP hash algorithm for 32 bits. 10 | func AP(str []byte) uint32 { 11 | var hash uint32 = 0 12 | for i := 0; i < len(str); i++ { 13 | if (i & 1) == 0 { 14 | hash ^= (hash << 7) ^ uint32(str[i]) ^ (hash >> 3) 15 | } else { 16 | hash ^= ^((hash << 11) ^ uint32(str[i]) ^ (hash >> 5)) + 1 17 | } 18 | } 19 | return hash 20 | } 21 | 22 | // AP64 implements the classic AP hash algorithm for 64 bits. 23 | func AP64(str []byte) uint64 { 24 | var hash uint64 = 0 25 | for i := 0; i < len(str); i++ { 26 | if (i & 1) == 0 { 27 | hash ^= (hash << 7) ^ uint64(str[i]) ^ (hash >> 3) 28 | } else { 29 | hash ^= ^((hash << 11) ^ uint64(str[i]) ^ (hash >> 5)) + 1 30 | } 31 | } 32 | return hash 33 | } 34 | -------------------------------------------------------------------------------- /net/gsel/gsel_selector_round_robin.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsel 8 | 9 | import ( 10 | "context" 11 | "sync" 12 | ) 13 | 14 | const SelectorRoundRobin = "BalancerRoundRobin" 15 | 16 | type selectorRoundRobin struct { 17 | mu sync.RWMutex 18 | nodes []Node 19 | next int 20 | } 21 | 22 | func NewSelectorRoundRobin() Selector { 23 | return &selectorRoundRobin{ 24 | nodes: make([]Node, 0), 25 | } 26 | } 27 | 28 | func (s *selectorRoundRobin) Update(nodes []Node) error { 29 | s.mu.Lock() 30 | s.nodes = nodes 31 | s.mu.Unlock() 32 | return nil 33 | } 34 | 35 | func (s *selectorRoundRobin) Pick(ctx context.Context) (node Node, done DoneFunc, err error) { 36 | s.mu.RLock() 37 | defer s.mu.RUnlock() 38 | node = s.nodes[s.next] 39 | s.next = (s.next + 1) % len(s.nodes) 40 | return 41 | } 42 | -------------------------------------------------------------------------------- /encoding/ghash/ghash_elf.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghash 8 | 9 | // ELF implements the classic ELF hash algorithm for 32 bits. 10 | func ELF(str []byte) uint32 { 11 | var hash uint32 = 0 12 | var x uint32 = 0 13 | for i := 0; i < len(str); i++ { 14 | hash = (hash << 4) + uint32(str[i]) 15 | if x = hash & 0xF0000000; x != 0 { 16 | hash ^= x >> 24 17 | hash &= ^x + 1 18 | } 19 | } 20 | return hash 21 | } 22 | 23 | // ELF64 implements the classic ELF hash algorithm for 64 bits. 24 | func ELF64(str []byte) uint64 { 25 | var ( 26 | hash uint64 = 0 27 | x uint64 = 0 28 | ) 29 | for i := 0; i < len(str); i++ { 30 | hash = (hash << 4) + uint64(str[i]) 31 | if x = hash & 0xF000000000000000; x != 0 { 32 | hash ^= x >> 24 33 | hash &= ^x + 1 34 | } 35 | } 36 | return hash 37 | } 38 | -------------------------------------------------------------------------------- /util/gutil/gutil_z_unit_struct_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gutil_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/frame/g" 13 | "github.com/gogf/gf/v2/test/gtest" 14 | "github.com/gogf/gf/v2/util/gutil" 15 | ) 16 | 17 | func Test_StructToSlice(t *testing.T) { 18 | type A struct { 19 | K1 int 20 | K2 string 21 | } 22 | gtest.C(t, func(t *gtest.T) { 23 | a := &A{ 24 | K1: 1, 25 | K2: "v2", 26 | } 27 | s := gutil.StructToSlice(a) 28 | t.Assert(len(s), 4) 29 | t.AssertIN(s[0], g.Slice{"K1", "K2", 1, "v2"}) 30 | t.AssertIN(s[1], g.Slice{"K1", "K2", 1, "v2"}) 31 | t.AssertIN(s[2], g.Slice{"K1", "K2", 1, "v2"}) 32 | t.AssertIN(s[3], g.Slice{"K1", "K2", 1, "v2"}) 33 | }) 34 | gtest.C(t, func(t *gtest.T) { 35 | s := gutil.StructToSlice(1) 36 | t.Assert(s, nil) 37 | }) 38 | } 39 | -------------------------------------------------------------------------------- /container/garray/garray_z_bench_any_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package garray_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/container/garray" 13 | ) 14 | 15 | type anySortedArrayItem struct { 16 | priority int64 17 | value interface{} 18 | } 19 | 20 | var ( 21 | anyArray = garray.NewArray() 22 | anySortedArray = garray.NewSortedArray(func(a, b interface{}) int { 23 | return int(a.(anySortedArrayItem).priority - b.(anySortedArrayItem).priority) 24 | }) 25 | ) 26 | 27 | func Benchmark_AnyArray_Add(b *testing.B) { 28 | for i := 0; i < b.N; i++ { 29 | anyArray.Append(i) 30 | } 31 | } 32 | 33 | func Benchmark_AnySortedArray_Add(b *testing.B) { 34 | for i := 0; i < b.N; i++ { 35 | anySortedArray.Add(anySortedArrayItem{ 36 | priority: int64(i), 37 | value: i, 38 | }) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /errors/gerror/gerror_option.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gerror 8 | 9 | import "github.com/gogf/gf/v2/errors/gcode" 10 | 11 | // Option is option for creating error. 12 | type Option struct { 13 | Error error // Wrapped error if any. 14 | Stack bool // Whether recording stack information into error. 15 | Text string // Error text, which is created by New* functions. 16 | Code gcode.Code // Error code if necessary. 17 | } 18 | 19 | // NewOption creates and returns an error with Option. 20 | // It is the senior usage for creating error, which is often used internally in framework. 21 | func NewOption(option Option) error { 22 | err := &Error{ 23 | error: option.Error, 24 | text: option.Text, 25 | code: option.Code, 26 | } 27 | if option.Stack { 28 | err.stack = callers() 29 | } 30 | return err 31 | } 32 | -------------------------------------------------------------------------------- /encoding/gcompress/gcompress_z_unit_zlib_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gcompress_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/encoding/gcompress" 13 | "github.com/gogf/gf/v2/test/gtest" 14 | ) 15 | 16 | func Test_Zlib_UnZlib(t *testing.T) { 17 | gtest.C(t, func(t *gtest.T) { 18 | src := "hello, world\n" 19 | dst := []byte{120, 156, 202, 72, 205, 201, 201, 215, 81, 40, 207, 47, 202, 73, 225, 2, 4, 0, 0, 255, 255, 33, 231, 4, 147} 20 | data, _ := gcompress.Zlib([]byte(src)) 21 | t.Assert(data, dst) 22 | 23 | data, _ = gcompress.UnZlib(dst) 24 | t.Assert(data, []byte(src)) 25 | 26 | data, _ = gcompress.Zlib(nil) 27 | t.Assert(data, nil) 28 | data, _ = gcompress.UnZlib(nil) 29 | t.Assert(data, nil) 30 | 31 | data, _ = gcompress.UnZlib(dst[1:]) 32 | t.Assert(data, nil) 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp_test 8 | 9 | import ( 10 | "strings" 11 | "testing" 12 | ) 13 | 14 | func Benchmark_TrimRightCharWithStrings(b *testing.B) { 15 | for i := 0; i < b.N; i++ { 16 | path := "//////////" 17 | path = strings.TrimRight(path, "/") 18 | } 19 | } 20 | 21 | func Benchmark_TrimRightCharWithSlice1(b *testing.B) { 22 | for i := 0; i < b.N; i++ { 23 | path := "//////////" 24 | for len(path) > 0 && path[len(path)-1] == '/' { 25 | path = path[:len(path)-1] 26 | } 27 | } 28 | } 29 | 30 | func Benchmark_TrimRightCharWithSlice2(b *testing.B) { 31 | for i := 0; i < b.N; i++ { 32 | path := "//////////" 33 | for { 34 | if length := len(path); length > 0 && path[length-1] == '/' { 35 | path = path[:length-1] 36 | } else { 37 | break 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /net/gsel/gsel_selector_random.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsel 8 | 9 | import ( 10 | "context" 11 | "sync" 12 | 13 | "github.com/gogf/gf/v2/util/grand" 14 | ) 15 | 16 | const SelectorRandom = "BalancerRandom" 17 | 18 | type selectorRandom struct { 19 | mu sync.RWMutex 20 | nodes []Node 21 | } 22 | 23 | func NewSelectorRandom() Selector { 24 | return &selectorRandom{ 25 | nodes: make([]Node, 0), 26 | } 27 | } 28 | 29 | func (s *selectorRandom) Update(nodes []Node) error { 30 | s.mu.Lock() 31 | defer s.mu.Unlock() 32 | s.nodes = nodes 33 | return nil 34 | } 35 | 36 | func (s *selectorRandom) Pick(ctx context.Context) (node Node, done DoneFunc, err error) { 37 | s.mu.RLock() 38 | defer s.mu.RUnlock() 39 | if len(s.nodes) == 0 { 40 | return nil, nil, nil 41 | } 42 | return s.nodes[grand.Intn(len(s.nodes))], nil, nil 43 | } 44 | -------------------------------------------------------------------------------- /os/gfile/gfile_time.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gfile 8 | 9 | import ( 10 | "os" 11 | "time" 12 | ) 13 | 14 | // MTime returns the modification time of file given by `path` in second. 15 | func MTime(path string) time.Time { 16 | s, e := os.Stat(path) 17 | if e != nil { 18 | return time.Time{} 19 | } 20 | return s.ModTime() 21 | } 22 | 23 | // MTimestamp returns the modification time of file given by `path` in second. 24 | func MTimestamp(path string) int64 { 25 | mtime := MTime(path) 26 | if mtime.IsZero() { 27 | return -1 28 | } 29 | return mtime.Unix() 30 | } 31 | 32 | // MTimestampMilli returns the modification time of file given by `path` in millisecond. 33 | func MTimestampMilli(path string) int64 { 34 | mtime := MTime(path) 35 | if mtime.IsZero() { 36 | return -1 37 | } 38 | return mtime.UnixNano() / 1000000 39 | } 40 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.MD: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ### 1. What version of `Go` and system type/arch are you using? 9 | 13 | 14 | 15 | ### 2. What version of `GoFrame` are you using? 16 | 17 | 18 | 19 | ### 3. Can this issue be re-produced with the latest release? 20 | 21 | 22 | 23 | ### 4. What did you do? 24 | 28 | 29 | 30 | 31 | ### 5. What did you expect to see? 32 | 33 | 34 | 35 | ### 6. What did you see instead? 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /database/gredis/gredis_z_unit_config_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gredis_test 8 | 9 | import ( 10 | "testing" 11 | "time" 12 | 13 | "github.com/gogf/gf/v2/database/gredis" 14 | "github.com/gogf/gf/v2/frame/g" 15 | "github.com/gogf/gf/v2/test/gtest" 16 | ) 17 | 18 | func Test_ConfigFromMap(t *testing.T) { 19 | gtest.C(t, func(t *gtest.T) { 20 | c, err := gredis.ConfigFromMap(g.Map{ 21 | `address`: `127.0.0.1:6379`, 22 | `db`: `10`, 23 | `pass`: `&*^%$#65Gv`, 24 | `minIdle`: `10`, 25 | `MaxIdle`: `100`, 26 | `ReadTimeout`: `10s`, 27 | }) 28 | t.AssertNil(err) 29 | t.Assert(c.Address, `127.0.0.1:6379`) 30 | t.Assert(c.Db, `10`) 31 | t.Assert(c.Pass, `&*^%$#65Gv`) 32 | t.Assert(c.MinIdle, 10) 33 | t.Assert(c.MaxIdle, 100) 34 | t.Assert(c.ReadTimeout, 10*time.Second) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /i18n/gi18n/gi18n_ctx.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gi18n implements internationalization and localization. 8 | package gi18n 9 | 10 | import "context" 11 | 12 | const ( 13 | ctxLanguage = "I18nLanguage" 14 | ) 15 | 16 | // WithLanguage append language setting to the context and returns a new context. 17 | func WithLanguage(ctx context.Context, language string) context.Context { 18 | if ctx == nil { 19 | ctx = context.TODO() 20 | } 21 | return context.WithValue(ctx, ctxLanguage, language) 22 | } 23 | 24 | // LanguageFromCtx retrieves and returns language name from context. 25 | // It returns an empty string if it is not set previously. 26 | func LanguageFromCtx(ctx context.Context) string { 27 | if ctx == nil { 28 | return "" 29 | } 30 | v := ctx.Value(ctxLanguage) 31 | if v != nil { 32 | return v.(string) 33 | } 34 | return "" 35 | } 36 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_request_param_router.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp 8 | 9 | import "github.com/gogf/gf/v2/container/gvar" 10 | 11 | // GetRouterMap retrieves and returns a copy of the router map. 12 | func (r *Request) GetRouterMap() map[string]string { 13 | if r.routerMap != nil { 14 | m := make(map[string]string, len(r.routerMap)) 15 | for k, v := range r.routerMap { 16 | m[k] = v 17 | } 18 | return m 19 | } 20 | return nil 21 | } 22 | 23 | // GetRouter retrieves and returns the router value with given key name `key`. 24 | // It returns `def` if `key` does not exist. 25 | func (r *Request) GetRouter(key string, def ...interface{}) *gvar.Var { 26 | if r.routerMap != nil { 27 | if v, ok := r.routerMap[key]; ok { 28 | return gvar.New(v) 29 | } 30 | } 31 | if len(def) > 0 { 32 | return gvar.New(def[0]) 33 | } 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /util/gconv/gconv_z_unit_custom_type_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gconv_test 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/frame/g" 11 | "github.com/gogf/gf/v2/test/gtest" 12 | "github.com/gogf/gf/v2/util/gconv" 13 | "testing" 14 | "time" 15 | ) 16 | 17 | type Duration time.Duration 18 | 19 | // UnmarshalText unmarshal text to duration. 20 | func (d *Duration) UnmarshalText(text []byte) error { 21 | tmp, err := time.ParseDuration(string(text)) 22 | if err == nil { 23 | *d = Duration(tmp) 24 | } 25 | return err 26 | } 27 | 28 | func Test_Struct_CustomTimeDuration_Attribute(t *testing.T) { 29 | type A struct { 30 | Name string 31 | Timeout Duration 32 | } 33 | gtest.C(t, func(t *gtest.T) { 34 | var a A 35 | err := gconv.Struct(g.Map{ 36 | "name": "john", 37 | "timeout": "1s", 38 | }, &a) 39 | t.AssertNil(err) 40 | }) 41 | } 42 | -------------------------------------------------------------------------------- /database/gdb/gdb_z_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gdb_test 8 | 9 | import ( 10 | "context" 11 | 12 | "github.com/gogf/gf/v2/database/gdb" 13 | "github.com/gogf/gf/v2/frame/g" 14 | ) 15 | 16 | func Example_transaction() { 17 | db.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error { 18 | // user 19 | result, err := tx.Insert("user", g.Map{ 20 | "passport": "john", 21 | "password": "12345678", 22 | "nickname": "JohnGuo", 23 | }) 24 | if err != nil { 25 | return err 26 | } 27 | // user_detail 28 | id, err := result.LastInsertId() 29 | if err != nil { 30 | return err 31 | } 32 | _, err = tx.Insert("user_detail", g.Map{ 33 | "uid": id, 34 | "site": "https://johng.cn", 35 | "true_name": "GuoQiang", 36 | }) 37 | if err != nil { 38 | return err 39 | } 40 | return nil 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /container/gvar/gvar_list.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gvar 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/util/gutil" 11 | ) 12 | 13 | // ListItemValues retrieves and returns the elements of all item struct/map with key `key`. 14 | // Note that the parameter `list` should be type of slice which contains elements of map or struct, 15 | // or else it returns an empty slice. 16 | func (v *Var) ListItemValues(key interface{}) (values []interface{}) { 17 | return gutil.ListItemValues(v.Val(), key) 18 | } 19 | 20 | // ListItemValuesUnique retrieves and returns the unique elements of all struct/map with key `key`. 21 | // Note that the parameter `list` should be type of slice which contains elements of map or struct, 22 | // or else it returns an empty slice. 23 | func (v *Var) ListItemValuesUnique(key string) []interface{} { 24 | return gutil.ListItemValuesUnique(v.Val(), key) 25 | } 26 | -------------------------------------------------------------------------------- /protocol/goai/goai_components.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | // Components is specified by OpenAPI/Swagger standard version 3.0. 10 | type Components struct { 11 | Schemas Schemas `json:"schemas,omitempty"` 12 | Parameters ParametersMap `json:"parameters,omitempty"` 13 | Headers Headers `json:"headers,omitempty"` 14 | RequestBodies RequestBodies `json:"requestBodies,omitempty"` 15 | Responses Responses `json:"responses,omitempty"` 16 | SecuritySchemes SecuritySchemes `json:"securitySchemes,omitempty"` 17 | Examples Examples `json:"examples,omitempty"` 18 | Links Links `json:"links,omitempty"` 19 | Callbacks Callbacks `json:"callbacks,omitempty"` 20 | } 21 | 22 | type ParametersMap map[string]*ParameterRef 23 | 24 | type RequestBodies map[string]*RequestBodyRef 25 | -------------------------------------------------------------------------------- /protocol/goai/goai_external_docs.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/internal/json" 11 | "github.com/gogf/gf/v2/text/gstr" 12 | "github.com/gogf/gf/v2/util/gconv" 13 | ) 14 | 15 | // ExternalDocs is specified by OpenAPI/Swagger standard version 3.0. 16 | type ExternalDocs struct { 17 | URL string `json:"url,omitempty"` 18 | Description string `json:"description,omitempty"` 19 | } 20 | 21 | func (ed *ExternalDocs) UnmarshalValue(value interface{}) error { 22 | var valueBytes = gconv.Bytes(value) 23 | if json.Valid(valueBytes) { 24 | return json.UnmarshalUseNumber(valueBytes, ed) 25 | } 26 | var ( 27 | valueString = string(valueBytes) 28 | valueArray = gstr.Split(valueString, "|") 29 | ) 30 | ed.URL = valueArray[0] 31 | if len(valueArray) > 1 { 32 | ed.Description = valueArray[1] 33 | } 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /example/trace/grpc_with_db/protocol/user/user.proto: -------------------------------------------------------------------------------- 1 | // protoc --gofast_out=plugins=grpc:. protocol/user/*.proto -I/Users/john/Workspace/Go/GOPATH/src -I/Users/john/Workspace/Go/GOPATH/src/gitee.com/johng/katyusha/.examples/tracing 2 | syntax = "proto3"; 3 | 4 | package user; 5 | 6 | option go_package = "protobuf/user"; 7 | 8 | import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 9 | 10 | // User service for tracing demo. 11 | service User { 12 | rpc Insert(InsertReq) returns (InsertRes) {} 13 | rpc Query(QueryReq) returns (QueryRes) {} 14 | rpc Delete(DeleteReq) returns (DeleteRes) {} 15 | } 16 | 17 | message InsertReq { 18 | string Name = 1 [(gogoproto.moretags) = 'v:"required#Please input user name."']; 19 | } 20 | 21 | message InsertRes { 22 | int32 Id = 1; 23 | } 24 | 25 | message QueryReq { 26 | int32 Id = 1 [(gogoproto.moretags) = 'v:"min:1#User id is required for querying."']; 27 | } 28 | 29 | message QueryRes { 30 | int32 Id = 1; 31 | string Name = 2; 32 | } 33 | 34 | message DeleteReq { 35 | int32 Id = 1 [(gogoproto.moretags) = 'v:"min:1#User id is required for deleting."']; 36 | } 37 | 38 | message DeleteRes {} -------------------------------------------------------------------------------- /internal/rwmutex/rwmutex_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package rwmutex_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/internal/rwmutex" 13 | ) 14 | 15 | var ( 16 | safeLock = rwmutex.New(true) 17 | unsafeLock = rwmutex.New(false) 18 | ) 19 | 20 | func Benchmark_Safe_LockUnlock(b *testing.B) { 21 | for i := 0; i < b.N; i++ { 22 | safeLock.Lock() 23 | safeLock.Unlock() 24 | } 25 | } 26 | 27 | func Benchmark_Safe_RLockRUnlock(b *testing.B) { 28 | for i := 0; i < b.N; i++ { 29 | safeLock.RLock() 30 | safeLock.RUnlock() 31 | } 32 | } 33 | 34 | func Benchmark_UnSafe_LockUnlock(b *testing.B) { 35 | for i := 0; i < b.N; i++ { 36 | unsafeLock.Lock() 37 | unsafeLock.Unlock() 38 | } 39 | } 40 | 41 | func Benchmark_UnSafe_RLockRUnlock(b *testing.B) { 42 | for i := 0; i < b.N; i++ { 43 | unsafeLock.RLock() 44 | unsafeLock.RUnlock() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /internal/utils/utils_list.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package utils 8 | 9 | import "fmt" 10 | 11 | // ListToMapByKey converts `list` to a map[string]interface{} of which key is specified by `key`. 12 | // Note that the item value may be type of slice. 13 | func ListToMapByKey(list []map[string]interface{}, key string) map[string]interface{} { 14 | var ( 15 | s = "" 16 | m = make(map[string]interface{}) 17 | tempMap = make(map[string][]interface{}) 18 | hasMultiValues bool 19 | ) 20 | for _, item := range list { 21 | if k, ok := item[key]; ok { 22 | s = fmt.Sprintf(`%v`, k) 23 | tempMap[s] = append(tempMap[s], item) 24 | if len(tempMap[s]) > 1 { 25 | hasMultiValues = true 26 | } 27 | } 28 | } 29 | for k, v := range tempMap { 30 | if hasMultiValues { 31 | m[k] = v 32 | } else { 33 | m[k] = v[0] 34 | } 35 | } 36 | return m 37 | } 38 | -------------------------------------------------------------------------------- /protocol/goai/goai_info.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | // Info is specified by OpenAPI/Swagger standard version 3.0. 10 | type Info struct { 11 | Title string `json:"title"` 12 | Description string `json:"description,omitempty"` 13 | TermsOfService string `json:"termsOfService,omitempty"` 14 | Contact *Contact `json:"contact,omitempty"` 15 | License *License `json:"license,omitempty"` 16 | Version string `json:"version"` 17 | } 18 | 19 | // Contact is specified by OpenAPI/Swagger standard version 3.0. 20 | type Contact struct { 21 | Name string `json:"name,omitempty"` 22 | URL string `json:"url,omitempty"` 23 | Email string `json:"email,omitempty"` 24 | } 25 | 26 | // License is specified by OpenAPI/Swagger standard version 3.0. 27 | type License struct { 28 | Name string `json:"name"` 29 | URL string `json:"url,omitempty"` 30 | } 31 | -------------------------------------------------------------------------------- /protocol/goai/goai_mediatype.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | // MediaType is specified by OpenAPI/Swagger 3.0 standard. 10 | type MediaType struct { 11 | Schema *SchemaRef `json:"schema,omitempty"` 12 | Example interface{} `json:"example,omitempty"` 13 | Examples Examples `json:"examples,omitempty"` 14 | Encoding map[string]*Encoding `json:"encoding,omitempty"` 15 | } 16 | 17 | // Content is specified by OpenAPI/Swagger 3.0 standard. 18 | type Content map[string]MediaType 19 | 20 | // Encoding is specified by OpenAPI/Swagger 3.0 standard. 21 | type Encoding struct { 22 | ContentType string `json:"contentType,omitempty"` 23 | Headers Headers `json:"headers,omitempty"` 24 | Style string `json:"style,omitempty"` 25 | Explode *bool `json:"explode,omitempty"` 26 | AllowReserved bool `json:"allowReserved,omitempty"` 27 | } 28 | -------------------------------------------------------------------------------- /net/gtrace/internal/provider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package provider 8 | 9 | import ( 10 | sdkTrace "go.opentelemetry.io/otel/sdk/trace" 11 | ) 12 | 13 | type TracerProvider struct { 14 | *sdkTrace.TracerProvider 15 | } 16 | 17 | // New returns a new and configured TracerProvider, which has no SpanProcessor. 18 | // 19 | // In default the returned TracerProvider is configured with: 20 | // - a ParentBased(AlwaysSample) Sampler 21 | // - a unix nano timestamp and random umber based IDGenerator 22 | // - the resource.Default() Resource 23 | // - the default SpanLimits. 24 | // 25 | // The passed opts are used to override these default values and configure the 26 | // returned TracerProvider appropriately. 27 | func New() *TracerProvider { 28 | return &TracerProvider{ 29 | TracerProvider: sdkTrace.NewTracerProvider( 30 | sdkTrace.WithIDGenerator(NewIDGenerator()), 31 | ), 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /os/gbuild/gbuild_z_unit_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gbuild_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/frame/g" 13 | "github.com/gogf/gf/v2/os/gbuild" 14 | "github.com/gogf/gf/v2/test/gtest" 15 | "github.com/gogf/gf/v2/util/gconv" 16 | ) 17 | 18 | func Test_Info(t *testing.T) { 19 | gtest.C(t, func(t *gtest.T) { 20 | t.Assert(gconv.Map(gbuild.Info()), g.Map{ 21 | "GoFrame": "", 22 | "Golang": "", 23 | "Git": "", 24 | "Time": "", 25 | "Data": g.Map{}, 26 | }) 27 | }) 28 | } 29 | 30 | func Test_Get(t *testing.T) { 31 | gtest.C(t, func(t *gtest.T) { 32 | t.Assert(gbuild.Get(`none`), nil) 33 | }) 34 | gtest.C(t, func(t *gtest.T) { 35 | t.Assert(gbuild.Get(`none`, 1), 1) 36 | }) 37 | } 38 | 39 | func Test_Map(t *testing.T) { 40 | gtest.C(t, func(t *gtest.T) { 41 | t.Assert(gbuild.Data(), map[string]interface{}{}) 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /os/grpool/grpool_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" 8 | 9 | package grpool_test 10 | 11 | import ( 12 | "context" 13 | "testing" 14 | 15 | "github.com/gogf/gf/v2/os/grpool" 16 | ) 17 | 18 | var ( 19 | ctx = context.TODO() 20 | n = 500000 21 | ) 22 | 23 | func increment(ctx context.Context) { 24 | for i := 0; i < 1000000; i++ { 25 | } 26 | } 27 | 28 | func BenchmarkGrpool_1(b *testing.B) { 29 | for i := 0; i < b.N; i++ { 30 | grpool.Add(ctx, increment) 31 | } 32 | } 33 | 34 | func BenchmarkGoroutine_1(b *testing.B) { 35 | for i := 0; i < b.N; i++ { 36 | go increment(ctx) 37 | } 38 | } 39 | 40 | func BenchmarkGrpool2(b *testing.B) { 41 | b.N = n 42 | for i := 0; i < b.N; i++ { 43 | grpool.Add(ctx, increment) 44 | } 45 | } 46 | 47 | func BenchmarkGoroutine2(b *testing.B) { 48 | b.N = n 49 | for i := 0; i < b.N; i++ { 50 | go increment(ctx) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 john@goframe.org https://goframe.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cmd/gf/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 john@goframe.org https://goframe.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /internal/mutex/mutex.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package mutex provides switch of concurrent safe feature for sync.Mutex. 8 | package mutex 9 | 10 | import "sync" 11 | 12 | // Mutex is a sync.Mutex with a switch for concurrent safe feature. 13 | type Mutex struct { 14 | sync.Mutex 15 | safe bool 16 | } 17 | 18 | // New creates and returns a new *Mutex. 19 | // The parameter `safe` is used to specify whether using this mutex in concurrent-safety, 20 | // which is false in default. 21 | func New(safe ...bool) *Mutex { 22 | mu := new(Mutex) 23 | if len(safe) > 0 { 24 | mu.safe = safe[0] 25 | } else { 26 | mu.safe = false 27 | } 28 | return mu 29 | } 30 | 31 | func (mu *Mutex) IsSafe() bool { 32 | return mu.safe 33 | } 34 | 35 | func (mu *Mutex) Lock() { 36 | if mu.safe { 37 | mu.Mutex.Lock() 38 | } 39 | } 40 | 41 | func (mu *Mutex) Unlock() { 42 | if mu.safe { 43 | mu.Mutex.Unlock() 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /os/gmlock/gmlock_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gmlock_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "github.com/gogf/gf/v2/os/gmlock" 13 | ) 14 | 15 | var ( 16 | lockKey = "This is the lock key for gmlock." 17 | ) 18 | 19 | func Benchmark_GMLock_Lock_Unlock(b *testing.B) { 20 | for i := 0; i < b.N; i++ { 21 | gmlock.Lock(lockKey) 22 | gmlock.Unlock(lockKey) 23 | } 24 | } 25 | 26 | func Benchmark_GMLock_RLock_RUnlock(b *testing.B) { 27 | for i := 0; i < b.N; i++ { 28 | gmlock.RLock(lockKey) 29 | gmlock.RUnlock(lockKey) 30 | } 31 | } 32 | 33 | func Benchmark_GMLock_TryLock_Unlock(b *testing.B) { 34 | for i := 0; i < b.N; i++ { 35 | if gmlock.TryLock(lockKey) { 36 | gmlock.Unlock(lockKey) 37 | } 38 | } 39 | } 40 | 41 | func Benchmark_GMLock_TryRLock_RUnlock(b *testing.B) { 42 | for i := 0; i < b.N; i++ { 43 | if gmlock.TryRLock(lockKey) { 44 | gmlock.RUnlock(lockKey) 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_z_example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp_test 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/frame/g" 11 | "github.com/gogf/gf/v2/net/ghttp" 12 | "github.com/gogf/gf/v2/os/gfile" 13 | ) 14 | 15 | func ExampleServer_Run() { 16 | s := g.Server() 17 | s.BindHandler("/", func(r *ghttp.Request) { 18 | r.Response.Write("hello world") 19 | }) 20 | s.SetPort(8999) 21 | s.Run() 22 | } 23 | 24 | // Custom saving file name. 25 | func ExampleUploadFile_Save() { 26 | s := g.Server() 27 | s.BindHandler("/upload", func(r *ghttp.Request) { 28 | file := r.GetUploadFile("TestFile") 29 | if file == nil { 30 | r.Response.Write("empty file") 31 | return 32 | } 33 | file.Filename = "MyCustomFileName.txt" 34 | fileName, err := file.Save(gfile.Temp()) 35 | if err != nil { 36 | r.Response.Write(err) 37 | return 38 | } 39 | r.Response.Write(fileName) 40 | }) 41 | s.SetPort(8999) 42 | s.Run() 43 | } 44 | -------------------------------------------------------------------------------- /protocol/goai/goai_link.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package goai 8 | 9 | import ( 10 | "github.com/gogf/gf/v2/internal/json" 11 | ) 12 | 13 | // Link is specified by OpenAPI/Swagger standard version 3.0. 14 | type Link struct { 15 | OperationID string `json:"operationId,omitempty"` 16 | OperationRef string `json:"operationRef,omitempty"` 17 | Description string `json:"description,omitempty"` 18 | Parameters map[string]interface{} `json:"parameters,omitempty"` 19 | Server *Server `json:"server,omitempty"` 20 | RequestBody interface{} `json:"requestBody,omitempty"` 21 | } 22 | 23 | type Links map[string]LinkRef 24 | 25 | type LinkRef struct { 26 | Ref string 27 | Value *Link 28 | } 29 | 30 | func (r LinkRef) MarshalJSON() ([]byte, error) { 31 | if r.Ref != "" { 32 | return formatRefToBytes(r.Ref), nil 33 | } 34 | return json.Marshal(r.Value) 35 | } 36 | -------------------------------------------------------------------------------- /text/gregex/gregex_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" 8 | 9 | package gregex_test 10 | 11 | import ( 12 | "regexp" 13 | "testing" 14 | 15 | "github.com/gogf/gf/v2/text/gregex" 16 | ) 17 | 18 | var pattern = `(\w+).+\-\-\s*(.+)` 19 | var src = `GF is best! -- John` 20 | 21 | func Benchmark_GF_IsMatchString(b *testing.B) { 22 | for i := 0; i < b.N; i++ { 23 | gregex.IsMatchString(pattern, src) 24 | } 25 | } 26 | 27 | func Benchmark_GF_MatchString(b *testing.B) { 28 | for i := 0; i < b.N; i++ { 29 | gregex.MatchString(pattern, src) 30 | } 31 | } 32 | 33 | func Benchmark_Compile(b *testing.B) { 34 | var wcdRegexp = regexp.MustCompile(pattern) 35 | for i := 0; i < b.N; i++ { 36 | wcdRegexp.MatchString(src) 37 | } 38 | } 39 | 40 | func Benchmark_Compile_Actual(b *testing.B) { 41 | for i := 0; i < b.N; i++ { 42 | wcdRegexp := regexp.MustCompile(pattern) 43 | wcdRegexp.MatchString(src) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /internal/fileinfo/fileinfo.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package fileinfo provides virtual os.FileInfo for given information. 8 | package fileinfo 9 | 10 | import ( 11 | "os" 12 | "time" 13 | ) 14 | 15 | type Info struct { 16 | name string 17 | size int64 18 | mode os.FileMode 19 | modTime time.Time 20 | } 21 | 22 | func New(name string, size int64, mode os.FileMode, modTime time.Time) *Info { 23 | return &Info{ 24 | name: name, 25 | size: size, 26 | mode: mode, 27 | modTime: modTime, 28 | } 29 | } 30 | 31 | func (i *Info) Name() string { 32 | return i.name 33 | } 34 | 35 | func (i *Info) Size() int64 { 36 | return i.size 37 | } 38 | 39 | func (i *Info) IsDir() bool { 40 | return i.mode.IsDir() 41 | } 42 | 43 | func (i *Info) Mode() os.FileMode { 44 | return i.mode 45 | } 46 | 47 | func (i *Info) ModTime() time.Time { 48 | return i.modTime 49 | } 50 | 51 | func (i *Info) Sys() interface{} { 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /frame/gins/gins_z_unit_server_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gins 8 | 9 | //func Test_Server(t *testing.T) { 10 | // gtest.C(t, func(t *gtest.T) { 11 | // var ( 12 | // path = gcfg.DefaultConfigFileName 13 | // serverConfigContent = gtest.DataContent("server", "config.yaml") 14 | // err = gfile.PutContents(path, serverConfigContent) 15 | // ) 16 | // t.AssertNil(err) 17 | // defer gfile.Remove(path) 18 | // 19 | // time.Sleep(time.Second) 20 | // 21 | // localInstances.Clear() 22 | // defer localInstances.Clear() 23 | // 24 | // s := Server("tempByInstanceName") 25 | // s.BindHandler("/", func(r *ghttp.Request) { 26 | // r.Response.Write("hello") 27 | // }) 28 | // s.SetDumpRouterMap(false) 29 | // t.AssertNil(s.Start()) 30 | // defer t.AssertNil(s.Shutdown()) 31 | // 32 | // content := HttpClient().GetContent(gctx.New(), `http://127.0.0.1:8003/`) 33 | // t.Assert(content, `hello`) 34 | // }) 35 | //} 36 | -------------------------------------------------------------------------------- /net/gipv4/gipv4_mac.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | // 7 | 8 | package gipv4 9 | 10 | import ( 11 | "net" 12 | 13 | "github.com/gogf/gf/v2/errors/gerror" 14 | ) 15 | 16 | // GetMac retrieves and returns the first mac address of current host. 17 | func GetMac() (mac string, err error) { 18 | macs, err := GetMacArray() 19 | if err != nil { 20 | return "", err 21 | } 22 | if len(macs) > 0 { 23 | return macs[0], nil 24 | } 25 | return "", nil 26 | } 27 | 28 | // GetMacArray retrieves and returns all the mac address of current host. 29 | func GetMacArray() (macs []string, err error) { 30 | netInterfaces, err := net.Interfaces() 31 | if err != nil { 32 | err = gerror.Wrap(err, `net.Interfaces failed`) 33 | return nil, err 34 | } 35 | for _, netInterface := range netInterfaces { 36 | macAddr := netInterface.HardwareAddr.String() 37 | if len(macAddr) == 0 { 38 | continue 39 | } 40 | macs = append(macs, macAddr) 41 | } 42 | return macs, nil 43 | } 44 | -------------------------------------------------------------------------------- /database/gdb/testdata/issue1412.sql: -------------------------------------------------------------------------------- 1 | -- ---------------------------- 2 | -- Table structure for items 3 | -- ---------------------------- 4 | CREATE TABLE `items` ( 5 | `id` int(11) NOT NULL, 6 | `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, 7 | PRIMARY KEY (`id`) USING BTREE 8 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 9 | 10 | -- ---------------------------- 11 | -- Records of items 12 | -- ---------------------------- 13 | INSERT INTO `items` VALUES (1, '金秋产品1'); 14 | INSERT INTO `items` VALUES (2, '金秋产品2'); 15 | 16 | -- ---------------------------- 17 | -- Table structure for parcels 18 | -- ---------------------------- 19 | CREATE TABLE `parcels` ( 20 | `id` int(11) NOT NULL AUTO_INCREMENT, 21 | `item_id` int(11) NULL DEFAULT NULL, 22 | PRIMARY KEY (`id`) USING BTREE 23 | ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 24 | 25 | -- ---------------------------- 26 | -- Records of parcels 27 | -- ---------------------------- 28 | INSERT INTO `parcels` VALUES (1, 1); 29 | INSERT INTO `parcels` VALUES (2, 2); 30 | INSERT INTO `parcels` VALUES (3, 0); -------------------------------------------------------------------------------- /net/gsvc/gsvc_registry.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gsvc 8 | 9 | import ( 10 | "context" 11 | 12 | "github.com/gogf/gf/v2/errors/gcode" 13 | "github.com/gogf/gf/v2/errors/gerror" 14 | ) 15 | 16 | // Register registers `service` to default registry.. 17 | func Register(ctx context.Context, service *Service) error { 18 | if defaultRegistry == nil { 19 | return gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) 20 | } 21 | ctx, cancel := context.WithTimeout(ctx, defaultTimeout) 22 | defer cancel() 23 | return defaultRegistry.Register(ctx, service) 24 | } 25 | 26 | // Deregister removes `service` from default registry. 27 | func Deregister(ctx context.Context, service *Service) error { 28 | if defaultRegistry == nil { 29 | return gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) 30 | } 31 | ctx, cancel := context.WithTimeout(ctx, defaultTimeout) 32 | defer cancel() 33 | return defaultRegistry.Deregister(ctx, service) 34 | } 35 | -------------------------------------------------------------------------------- /container/gqueue/gqueue_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" -benchmem 8 | 9 | package gqueue_test 10 | 11 | import ( 12 | "testing" 13 | 14 | "github.com/gogf/gf/v2/container/gqueue" 15 | ) 16 | 17 | var bn = 20000000 18 | var length = 1000000 19 | var qstatic = gqueue.New(length) 20 | var qdynamic = gqueue.New() 21 | var cany = make(chan interface{}, length) 22 | 23 | func Benchmark_Gqueue_StaticPushAndPop(b *testing.B) { 24 | b.N = bn 25 | for i := 0; i < b.N; i++ { 26 | qstatic.Push(i) 27 | qstatic.Pop() 28 | } 29 | } 30 | 31 | func Benchmark_Gqueue_DynamicPush(b *testing.B) { 32 | b.N = bn 33 | for i := 0; i < b.N; i++ { 34 | qdynamic.Push(i) 35 | } 36 | } 37 | 38 | func Benchmark_Gqueue_DynamicPop(b *testing.B) { 39 | b.N = bn 40 | for i := 0; i < b.N; i++ { 41 | qdynamic.Pop() 42 | } 43 | } 44 | 45 | func Benchmark_Channel_PushAndPop(b *testing.B) { 46 | b.N = bn 47 | for i := 0; i < b.N; i++ { 48 | cany <- i 49 | <-cany 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /frame/gins/testdata/redis/config.toml: -------------------------------------------------------------------------------- 1 | # 模板引擎目录 2 | viewpath = "/home/www/templates/" 3 | test = "v=3" 4 | # MySQL数据库配置 5 | [database] 6 | [[database.default]] 7 | host = "127.0.0.1" 8 | port = "3306" 9 | user = "root" 10 | pass = "" 11 | # pass = "12345678" 12 | name = "test" 13 | type = "mysql" 14 | role = "master" 15 | charset = "utf8" 16 | priority = "1" 17 | [[database.test]] 18 | host = "127.0.0.1" 19 | port = "3306" 20 | user = "root" 21 | pass = "" 22 | # pass = "12345678" 23 | name = "test" 24 | type = "mysql" 25 | role = "master" 26 | charset = "utf8" 27 | priority = "1" 28 | # Redis数据库配置 29 | [redis] 30 | [redis.default] 31 | address = "127.0.0.1:6379" 32 | db = 7 33 | [redis.cache] 34 | address = "127.0.0.1:6379" 35 | db = 8 36 | [redis.disk] 37 | address = "127.0.0.1:6379" 38 | db = 9 39 | maxIdle = 1 40 | maxActive = 10 41 | idleTimeout = "10s" 42 | maxConnLifetime = "10s" 43 | 44 | -------------------------------------------------------------------------------- /util/gutil/gutil_struct.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gutil 8 | 9 | import ( 10 | "reflect" 11 | 12 | "github.com/gogf/gf/v2/util/gconv" 13 | ) 14 | 15 | // StructToSlice converts struct to slice of which all keys and values are its items. 16 | // Eg: {"K1": "v1", "K2": "v2"} => ["K1", "v1", "K2", "v2"] 17 | func StructToSlice(data interface{}) []interface{} { 18 | var ( 19 | reflectValue = reflect.ValueOf(data) 20 | reflectKind = reflectValue.Kind() 21 | ) 22 | for reflectKind == reflect.Ptr { 23 | reflectValue = reflectValue.Elem() 24 | reflectKind = reflectValue.Kind() 25 | } 26 | switch reflectKind { 27 | case reflect.Struct: 28 | array := make([]interface{}, 0) 29 | // Note that, it uses the gconv tag name instead of the attribute name if 30 | // the gconv tag is fined in the struct attributes. 31 | for k, v := range gconv.Map(reflectValue) { 32 | array = append(array, k) 33 | array = append(array, v) 34 | } 35 | return array 36 | } 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_z_unit_feature_context_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp_test 8 | 9 | import ( 10 | "fmt" 11 | "testing" 12 | "time" 13 | 14 | "github.com/gogf/gf/v2/frame/g" 15 | "github.com/gogf/gf/v2/net/ghttp" 16 | "github.com/gogf/gf/v2/test/gtest" 17 | "github.com/gogf/gf/v2/util/guid" 18 | ) 19 | 20 | func Test_Context(t *testing.T) { 21 | s := g.Server(guid.S()) 22 | s.Group("/", func(group *ghttp.RouterGroup) { 23 | group.Middleware(func(r *ghttp.Request) { 24 | r.SetCtxVar("traceid", 123) 25 | r.Middleware.Next() 26 | }) 27 | group.GET("/", func(r *ghttp.Request) { 28 | r.Response.Write(r.GetCtxVar("traceid")) 29 | }) 30 | }) 31 | s.SetDumpRouterMap(false) 32 | s.Start() 33 | defer s.Shutdown() 34 | 35 | time.Sleep(100 * time.Millisecond) 36 | gtest.C(t, func(t *gtest.T) { 37 | client := g.Client() 38 | client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) 39 | 40 | t.Assert(client.GetContent(ctx, "/"), `123`) 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /os/gfile/gfile_sort.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gfile 8 | 9 | import ( 10 | "strings" 11 | 12 | "github.com/gogf/gf/v2/container/garray" 13 | ) 14 | 15 | // fileSortFunc is the comparison function for files. 16 | // It sorts the array in order of: directory -> file. 17 | // If `path1` and `path2` are the same type, it then sorts them as strings. 18 | func fileSortFunc(path1, path2 string) int { 19 | isDirPath1 := IsDir(path1) 20 | isDirPath2 := IsDir(path2) 21 | if isDirPath1 && !isDirPath2 { 22 | return -1 23 | } 24 | if !isDirPath1 && isDirPath2 { 25 | return 1 26 | } 27 | if n := strings.Compare(path1, path2); n != 0 { 28 | return n 29 | } else { 30 | return -1 31 | } 32 | } 33 | 34 | // SortFiles sorts the `files` in order of: directory -> file. 35 | // Note that the item of `files` should be absolute path. 36 | func SortFiles(files []string) []string { 37 | array := garray.NewSortedStrArrayComparator(fileSortFunc) 38 | array.Add(files...) 39 | return array.Slice() 40 | } 41 | -------------------------------------------------------------------------------- /database/gredis/gredis_instance.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gredis 8 | 9 | import ( 10 | "context" 11 | 12 | "github.com/gogf/gf/v2/container/gmap" 13 | "github.com/gogf/gf/v2/internal/intlog" 14 | ) 15 | 16 | var ( 17 | localInstances = gmap.NewStrAnyMap(true) 18 | ) 19 | 20 | // Instance returns an instance of redis client with specified group. 21 | // The `name` param is unnecessary, if `name` is not passed, 22 | // it returns a redis instance with default configuration group. 23 | func Instance(name ...string) *Redis { 24 | group := DefaultGroupName 25 | if len(name) > 0 && name[0] != "" { 26 | group = name[0] 27 | } 28 | v := localInstances.GetOrSetFuncLock(group, func() interface{} { 29 | if config, ok := GetConfig(group); ok { 30 | r, err := New(config) 31 | if err != nil { 32 | intlog.Errorf(context.TODO(), `%+v`, err) 33 | return nil 34 | } 35 | return r 36 | } 37 | return nil 38 | }) 39 | if v != nil { 40 | return v.(*Redis) 41 | } 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /os/gfsnotify/gfsnotify_event.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // ThIs Source Code Form Is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not dIstributed with thIs file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gfsnotify 8 | 9 | // String returns current event as string. 10 | func (e *Event) String() string { 11 | return e.event.String() 12 | } 13 | 14 | // IsCreate checks whether current event contains file/folder create event. 15 | func (e *Event) IsCreate() bool { 16 | return e.Op == 1 || e.Op&CREATE == CREATE 17 | } 18 | 19 | // IsWrite checks whether current event contains file/folder write event. 20 | func (e *Event) IsWrite() bool { 21 | return e.Op&WRITE == WRITE 22 | } 23 | 24 | // IsRemove checks whether current event contains file/folder remove event. 25 | func (e *Event) IsRemove() bool { 26 | return e.Op&REMOVE == REMOVE 27 | } 28 | 29 | // IsRename checks whether current event contains file/folder rename event. 30 | func (e *Event) IsRename() bool { 31 | return e.Op&RENAME == RENAME 32 | } 33 | 34 | // IsChmod checks whether current event contains file/folder chmod event. 35 | func (e *Event) IsChmod() bool { 36 | return e.Op&CHMOD == CHMOD 37 | } 38 | -------------------------------------------------------------------------------- /database/gdb/testdata/with_multiple_depends.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE TABLE `table_a` ( 3 | `id` int(11) NOT NULL AUTO_INCREMENT, 4 | `alias` varchar(255) NULL DEFAULT '', 5 | PRIMARY KEY (`id`) USING BTREE 6 | ) ENGINE = InnoDB; 7 | 8 | INSERT INTO `table_a` VALUES (1, 'table_a_test1'); 9 | INSERT INTO `table_a` VALUES (2, 'table_a_test2'); 10 | 11 | CREATE TABLE `table_b` ( 12 | `id` int(11) NOT NULL AUTO_INCREMENT, 13 | `table_a_id` int(11) NOT NULL, 14 | `alias` varchar(255) NULL DEFAULT '', 15 | PRIMARY KEY (`id`) USING BTREE 16 | ) ENGINE = InnoDB; 17 | 18 | INSERT INTO `table_b` VALUES (10, 1, 'table_b_test1'); 19 | INSERT INTO `table_b` VALUES (20, 2, 'table_b_test2'); 20 | INSERT INTO `table_b` VALUES (30, 1, 'table_b_test3'); 21 | INSERT INTO `table_b` VALUES (40, 2, 'table_b_test4'); 22 | 23 | CREATE TABLE `table_c` ( 24 | `id` int(11) NOT NULL AUTO_INCREMENT, 25 | `table_b_id` int(11) NOT NULL, 26 | `alias` varchar(255) NULL DEFAULT '', 27 | PRIMARY KEY (`id`) USING BTREE 28 | ) ENGINE = InnoDB; 29 | 30 | INSERT INTO `table_c` VALUES (100, 10, 'table_c_test1'); 31 | INSERT INTO `table_c` VALUES (200, 10, 'table_c_test2'); 32 | INSERT INTO `table_c` VALUES (300, 20, 'table_c_test3'); 33 | INSERT INTO `table_c` VALUES (400, 30, 'table_c_test4'); -------------------------------------------------------------------------------- /encoding/gjson/gjson_implements.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gjson 8 | 9 | // MarshalJSON implements the interface MarshalJSON for json.Marshal. 10 | func (j Json) MarshalJSON() ([]byte, error) { 11 | return j.ToJson() 12 | } 13 | 14 | // UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal. 15 | func (j *Json) UnmarshalJSON(b []byte) error { 16 | r, err := LoadContent(b) 17 | if r != nil { 18 | // Value copy. 19 | *j = *r 20 | } 21 | return err 22 | } 23 | 24 | // UnmarshalValue is an interface implement which sets any type of value for Json. 25 | func (j *Json) UnmarshalValue(value interface{}) error { 26 | if r := New(value); r != nil { 27 | // Value copy. 28 | *j = *r 29 | } 30 | return nil 31 | } 32 | 33 | // MapStrAny implements interface function MapStrAny(). 34 | func (j *Json) MapStrAny() map[string]interface{} { 35 | return j.Map() 36 | } 37 | 38 | // Interfaces implements interface function Interfaces(). 39 | func (j *Json) Interfaces() []interface{} { 40 | return j.Array() 41 | } 42 | -------------------------------------------------------------------------------- /internal/utils/utils_map.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package utils 8 | 9 | // MapPossibleItemByKey tries to find the possible key-value pair for given key ignoring cases and symbols. 10 | // 11 | // Note that this function might be of low performance. 12 | func MapPossibleItemByKey(data map[string]interface{}, key string) (foundKey string, foundValue interface{}) { 13 | if len(data) == 0 { 14 | return 15 | } 16 | if v, ok := data[key]; ok { 17 | return key, v 18 | } 19 | // Loop checking. 20 | for k, v := range data { 21 | if EqualFoldWithoutChars(k, key) { 22 | return k, v 23 | } 24 | } 25 | return "", nil 26 | } 27 | 28 | // MapContainsPossibleKey checks if the given `key` is contained in given map `data`. 29 | // It checks the key ignoring cases and symbols. 30 | // 31 | // Note that this function might be of low performance. 32 | func MapContainsPossibleKey(data map[string]interface{}, key string) bool { 33 | if k, _ := MapPossibleItemByKey(data, key); k != "" { 34 | return true 35 | } 36 | return false 37 | } 38 | -------------------------------------------------------------------------------- /container/glist/glist_z_bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // go test *.go -bench=".*" -benchmem 8 | 9 | package glist 10 | 11 | import ( 12 | "testing" 13 | ) 14 | 15 | var ( 16 | l = New(true) 17 | ) 18 | 19 | func Benchmark_PushBack(b *testing.B) { 20 | b.RunParallel(func(pb *testing.PB) { 21 | i := 0 22 | for pb.Next() { 23 | l.PushBack(i) 24 | i++ 25 | } 26 | }) 27 | } 28 | 29 | func Benchmark_PushFront(b *testing.B) { 30 | b.RunParallel(func(pb *testing.PB) { 31 | i := 0 32 | for pb.Next() { 33 | l.PushFront(i) 34 | i++ 35 | } 36 | }) 37 | } 38 | 39 | func Benchmark_Len(b *testing.B) { 40 | b.RunParallel(func(pb *testing.PB) { 41 | for pb.Next() { 42 | l.Len() 43 | } 44 | }) 45 | } 46 | 47 | func Benchmark_PopFront(b *testing.B) { 48 | b.RunParallel(func(pb *testing.PB) { 49 | for pb.Next() { 50 | l.PopFront() 51 | } 52 | }) 53 | } 54 | 55 | func Benchmark_PopBack(b *testing.B) { 56 | b.RunParallel(func(pb *testing.PB) { 57 | for pb.Next() { 58 | l.PopBack() 59 | } 60 | }) 61 | } 62 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_z_unit_feature_ip_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // static service testing. 8 | 9 | package ghttp_test 10 | 11 | import ( 12 | "fmt" 13 | "testing" 14 | "time" 15 | 16 | "github.com/gogf/gf/v2/frame/g" 17 | "github.com/gogf/gf/v2/net/ghttp" 18 | "github.com/gogf/gf/v2/test/gtest" 19 | "github.com/gogf/gf/v2/util/guid" 20 | ) 21 | 22 | func TestRequest_GetRemoteIp(t *testing.T) { 23 | gtest.C(t, func(t *gtest.T) { 24 | s := g.Server(guid.S()) 25 | s.BindHandler("/", func(r *ghttp.Request) { 26 | r.Response.Write(r.GetRemoteIp()) 27 | }) 28 | s.SetDumpRouterMap(false) 29 | s.Start() 30 | defer s.Shutdown() 31 | 32 | time.Sleep(100 * time.Millisecond) 33 | 34 | clientV4 := g.Client() 35 | clientV4.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) 36 | 37 | clientV6 := g.Client() 38 | clientV6.SetPrefix(fmt.Sprintf("http://[::1]:%d", s.GetListenedPort())) 39 | 40 | t.Assert(clientV4.GetContent(ctx, "/"), "127.0.0.1") 41 | t.Assert(clientV6.GetContent(ctx, "/"), "::1") 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /net/ghttp/ghttp_z_unit_feature_request_ctx_test.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package ghttp_test 8 | 9 | import ( 10 | "context" 11 | "fmt" 12 | "testing" 13 | "time" 14 | 15 | "github.com/gogf/gf/v2/frame/g" 16 | "github.com/gogf/gf/v2/net/ghttp" 17 | "github.com/gogf/gf/v2/test/gtest" 18 | "github.com/gogf/gf/v2/util/guid" 19 | ) 20 | 21 | func Test_Request_SetCtx(t *testing.T) { 22 | s := g.Server(guid.S()) 23 | s.Group("/", func(group *ghttp.RouterGroup) { 24 | group.Middleware(func(r *ghttp.Request) { 25 | ctx := context.WithValue(r.Context(), "test", 1) 26 | r.SetCtx(ctx) 27 | r.Middleware.Next() 28 | }) 29 | group.ALL("/", func(r *ghttp.Request) { 30 | r.Response.Write(r.Context().Value("test")) 31 | }) 32 | }) 33 | s.SetDumpRouterMap(false) 34 | s.Start() 35 | defer s.Shutdown() 36 | 37 | time.Sleep(100 * time.Millisecond) 38 | gtest.C(t, func(t *gtest.T) { 39 | c := g.Client() 40 | c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) 41 | 42 | t.Assert(c.GetContent(ctx, "/"), "1") 43 | }) 44 | } 45 | -------------------------------------------------------------------------------- /os/gctx/gctx.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | // Package gctx wraps context.Context and provides extra context features. 8 | package gctx 9 | 10 | import ( 11 | "context" 12 | 13 | "github.com/gogf/gf/v2/net/gtrace" 14 | ) 15 | 16 | type ( 17 | Ctx = context.Context // Ctx is short name alias for context.Context. 18 | StrKey string // StrKey is a type for warps basic type string as context key. 19 | ) 20 | 21 | // New creates and returns a context which contains context id. 22 | func New() context.Context { 23 | return WithCtx(context.Background()) 24 | } 25 | 26 | // WithCtx creates and returns a context containing context id upon given parent context `ctx`. 27 | func WithCtx(ctx context.Context) context.Context { 28 | if gtrace.IsUsingDefaultProvider() { 29 | var span *gtrace.Span 30 | ctx, span = gtrace.NewSpan(ctx, "gctx.WithCtx") 31 | defer span.End() 32 | } 33 | return ctx 34 | } 35 | 36 | // CtxId retrieves and returns the context id from context. 37 | func CtxId(ctx context.Context) string { 38 | return gtrace.GetTraceID(ctx) 39 | } 40 | -------------------------------------------------------------------------------- /database/gdb/testdata/issue1401.sql: -------------------------------------------------------------------------------- 1 | -- ---------------------------- 2 | -- Table structure for parcel_items 3 | -- ---------------------------- 4 | DROP TABLE IF EXISTS `parcel_items`; 5 | CREATE TABLE `parcel_items` ( 6 | `id` int(11) NOT NULL, 7 | `parcel_id` int(11) NULL DEFAULT NULL, 8 | `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, 9 | PRIMARY KEY (`id`) USING BTREE 10 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 11 | 12 | -- ---------------------------- 13 | -- Records of parcel_items 14 | -- ---------------------------- 15 | INSERT INTO `parcel_items` VALUES (1, 1, '新品'); 16 | INSERT INTO `parcel_items` VALUES (2, 3, '新品2'); 17 | 18 | -- ---------------------------- 19 | -- Table structure for parcels 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `parcels`; 22 | CREATE TABLE `parcels` ( 23 | `id` int(11) NOT NULL AUTO_INCREMENT, 24 | PRIMARY KEY (`id`) USING BTREE 25 | ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 26 | 27 | -- ---------------------------- 28 | -- Records of parcels 29 | -- ---------------------------- 30 | INSERT INTO `parcels` VALUES (1); 31 | INSERT INTO `parcels` VALUES (2); 32 | INSERT INTO `parcels` VALUES (3); -------------------------------------------------------------------------------- /os/gcache/gcache_adapter_memory_expire_times.go: -------------------------------------------------------------------------------- 1 | // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the MIT License. 4 | // If a copy of the MIT was not distributed with this file, 5 | // You can obtain one at https://github.com/gogf/gf. 6 | 7 | package gcache 8 | 9 | import ( 10 | "sync" 11 | ) 12 | 13 | type adapterMemoryExpireTimes struct { 14 | mu sync.RWMutex // expireTimeMu ensures the concurrent safety of expireTimes map. 15 | expireTimes map[interface{}]int64 // expireTimes is the expiring key to its timestamp mapping, which is used for quick indexing and deleting. 16 | } 17 | 18 | func newAdapterMemoryExpireTimes() *adapterMemoryExpireTimes { 19 | return &adapterMemoryExpireTimes{ 20 | expireTimes: make(map[interface{}]int64), 21 | } 22 | } 23 | 24 | func (d *adapterMemoryExpireTimes) Get(key interface{}) (value int64) { 25 | d.mu.RLock() 26 | value = d.expireTimes[key] 27 | d.mu.RUnlock() 28 | return 29 | } 30 | 31 | func (d *adapterMemoryExpireTimes) Set(key interface{}, value int64) { 32 | d.mu.Lock() 33 | d.expireTimes[key] = value 34 | d.mu.Unlock() 35 | } 36 | 37 | func (d *adapterMemoryExpireTimes) Delete(key interface{}) { 38 | d.mu.Lock() 39 | delete(d.expireTimes, key) 40 | d.mu.Unlock() 41 | } 42 | --------------------------------------------------------------------------------