Golang/XGo interpreter. Base on ixgo v0.52.0
-
Run the Golang WITHOUT Golang compiler(150MB+)
-
Only 18MB after built and UPX -9
-
Golang v1.24
-
XGo script file (*.xgo, *.gop)
-
Golang file
-
Golang project
-
Golang project in an archive file of
*.tar.gz,*.tar.xz, ... -
Support shebang line, like
#!/usr/bin/bash -
Generic Function
-
main.goin the subdirectory -
*.asmfile support
- Run golang files
- Execute code
- REPL
- Run as shell file
gos <PATH>
[-V | --debug]
-- <arguments>
Run a XGo script, or a Golang project
| Type | Default | ||
|---|---|---|---|
| <PATH> | String | File of Golang+ script, "*.xgo". Directory of Golang project. |
|
| -V --debug |
Boolean | false | Print the debug information. |
| -- <arguments> | arguments for script. Be read os.Args in the script. |
Advanced options
-
--vendor: The path of Golang dependency packages.gos run . --vendor=/path/to/vendor -
-I | --import <NAME=PATH>: The package to be imported.gos run . -I mathex=/path/to/mathx -I json2=/path/to/json2 -
-p | --plugin <path>: (Only for linux)Load the "*.so" of golang plugingos run . --plugin /path/to/plugin1.so --plugin /path/to/plugin2.so
Run a file with *.xgo、*.go
.gomust bepackage mainand includesfunc main()
Run
gos /path/to/file.xgoRun in the working directory
cd /path/to
gos file.xgoWith arguments
gos file.xgo -- --abc 123 --def- Must be
package mainand Onefunc main()in the working directory - The
.xgofile implicitly contains afunc main(), which is why only one.xgofile is allowed.
/path/to/
- func.go
- func.xgo
- main.go
Run
gos /path/to/examples/example3Run in the working directory
cd /path/to/examples/example3
gos .With arguments
gos . -- --abc 123 --def- No allowed
*.xgo go.modMUST be in the working directoryvendor/modules.txtMUST be in the working directory, if you need 3rd-party modules
/path/to
- main.go
- func/
- func.go
- go.mod
- vensor/ <--- if you need 3rd-party modules
- modules.txt
A packaging of project
Supported archive format. When it runs, it'll actually be extract to examples/__FILE_NAME__
- tar.gz
- tar.bzip2
- tar.xz
- zip
- tar
Run an archive
gos examples/example5.tar.gzWith arguments
gos examples2/2.go -- --abc 123 --defgos
[-s | --script <code>]
[--debug]
-- <script arguments>
Execute script code from StdIn or the argument of "--script"
| Type | Default | ||
|---|---|---|---|
| -V --debug |
false | Print the debug information. | |
| -s --script <code> |
String | The Golang/XGo script as string | |
| -- <arguments> | arguments for script. Be read os.Args in the script. |
gos < example2/1.xgocat example2/1.xgo | gosecho "i := 1+2; println(i)" | gos
printf "i := 1+2 \n println(i)" | gos$ gos -s "i := 1+2; println(i)"
Use
;(semicolons) instead of carriage returns
gos repl
A XGo Read Eval Print Loop
Online: https://repl.xgo.dev/
Shebang line:
script.sh
///usr/bin/true; exec /usr/bin/gos -- "$0" "$@"
import "os"
import "fmt"
fmt.Printf("%v", os.Args)
The first two lines are important
Run
$ chmod +x ./script.sh
$ ./scrpit.sh --argument1 --argument2
$ sh ./script.sh --argument1 --argument2
[./script.sh.xgo --argument1 --argument2]
go install github.com/goplus/ixgo/cmd/qexp@latestqexp -outdir pkgs -filename go_export github.com/inconshreveable/mousetrap github.com/spf13/pflag github.com/spf13/cobra go.uber.org/multierr gopkg.in/yaml.v3 github.com/pkg/errors
go build