How to call packages in the Go language standard library or other third-party packages in Gox language-GX16

Gox language supports most of the Go language standard library, and it can be directly quoted when needed, without importing or explicit declaration. For example, in this example, the Now function of the time package in the Go language standard library is used to obtain the current system time, and then the Add and Sub functions in the time package are used to add and subtract time. Note that in Gox language, it is agreed that general functions start with lowercase letters, and structures or member variables start with uppercase letters. This is slightly different from the Go language, so the Now function becomes a lowercase start. In addition, if the package used is multi-level, it is generally quoted in the following way:

net_http.Client

That is, if you quote the original "net/http" package, you need to replace the slash character with an underscore to become "net_http".

If you don’t have a package after trying, you can compile Gox's source code to add some packages you need, or remove some unnecessary packages to reduce the size of the main program.

The referenced third-party package also has similar rules. The only special agreement is that if the third-party package is under github.com, for example, github.com/myname/pkgname, remove .com after github and become github_myname_pkgname. Most other names with the domain name as the root directory are handled similarly. The tk package is the only special package. You don’t need to call it with the full name github_topxeq_tk, just use tk. There are similar packages such as github.com/topxeq/sqltk and github.com/topxeq/imagetk.

You can also define your own abbreviations to simplify references to packages with longer names, for example:

t = tk
u = net_url

v = make(u.Values)

v.Set("a", "123")

t.Pl("%#v", v)

The tk package and net/url package are replaced with variables t and u respectively in the code, which makes the code relatively concise, but be careful not to make the code readable. The result of the execution is:

λ gox test.gox
url.Values{"a":[]string{"123"}}

Guess you like

Origin blog.csdn.net/weixin_41462458/article/details/107943103