Golang/Go+ interpreter. Base on igop v0.9.6
- Run the Golang project WITHOUT Golang compiler(142MB)
- Only 25MB after built and UPX
- Real time & Run:
- Go+ script file, or a Golang file
- Golang project (3rd party modules require a vendor directory)
- a Golang project in the archive file of
*.tar.gz
,*.tar.xz
, ...
- Support shebang line, like
#!/usr/bin/bash
- Go+ Read-Eval-Print-Loop
- Go1.18, Go1.19 generics
- igop run: run golang files
- igop exec: execute script code
- igop repl: REPL
- bash ./script.sh: run as shell file
igop run <PATH>
[-V | --debug]
[--vendor <path>]
[-I | --import NAME=PATH]
[-p | --plugin <path>]
-- <arguments>
Run a Go+ script, or a Golang project
Type | Default | ||
---|---|---|---|
String | File of Golang+ script, "*.gop". Directory of Golang project. |
||
-V --debug |
Boolean | false | Print the debug information. |
--vendor | String | /vendor | The path of Golang dependency packages. Generate by go mod vendor . |
-I --import |
NAME=PATH | The package to be imported. -I PACKAGE_NAME=PATH -I PACKAGE_NAME2=PATH2 . |
|
-p --plugin <path> |
Array | (Only for linux)Load the "*.so" of golang plugin, See https://github.com/fly-studio/igop_plugins | |
-- <arguments> | arguments for script. Be read os.Args in the script. |
$ igop run /path/to/file.gop
# or
$ cd /path/to
$ igop run file.gop
The difference is that they have different Working directories
Similarly hereinafter.
Golang file, Must include package main
and func main()
package main
func main() {
}
$ igop run /path/to/file.go
- The package MUST be
package main
in all.go
files - Included
func main()
in anyone.go
file, or ONLY one.gop
file - No sub-folder. even if the sub-folders are present, they will be ignored
- Support Go/Go+ hybrid programming
/path/to/
- func.go
- func.gop
- main.go
ONLY allowed one
func main(){}
, Whether in the *.gop or *.go, See examples/example3
Run
$ cd /path/to
$ igop run .
# or
$ igop run /path/to
If the Golang project contains submodules, or 3rd party modules.
Not allowed *.gop(Temporary)
/path/to
- main.go
- func/
- func.go
MUST include these files
/path/to/
- go.mod
- vendor/ <--- if you need 3rd-party modules
- modules.txt
Init the project to generate go.mod
at first
$ go mod init your project-name
Run this command to create the vendor directory,
igop
need to load the modules from vendor/modules.txt
$ go mod vendor
This is a convenient way that a packaging of project mode
Support archive format.
- tar.gz
- tar.bzip2
- tar.xz
- zip
- tar
When it's running, it's actually being extract to example1/__example1.tar.gz__
$ igop run examples1/example1.tar.gz --vendor vendor
Unless you specify an absolute path that mean path on the OS, --vendor
would be a relative path in archive.
Same with the PATH of --import NAME=PATH
.
the argument of
--vendor vendor
mean the vendor path isexamples1/__example1.tar.gz__/vendor
Use the vendor with absolute path in OS
$ igop run examples1/example1.tar.gz --vendor /path/to/vendor
See "example1/"、"example2/"、"example3/"
Project mode without modules
$ igop run example3/
$ cd example3/
$ igop run .
Project mode with modules
$ igop run example1/
$ igop run example1/ --vendor example1/vendor
$ cd example1/
$ igop run . --vendor vendor
Single mode
$ igop run examples2/1.gop
Script arguments
$ igop run examples2/2.go -- --abc 123 --def
igop exec
[-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/Go+ script as string | |
-- <arguments> | arguments for script. Be read os.Args in the script. |
$ igop exec < example2/1.gop
$ cat example2/1.gop | igop exec
$ echo "i := 1+2; println(i)" | igop exec
$ printf "i := 1+2 \n println(i)" | igop exec
$ igop exec -s "i := 1+2; println(i)"
Use
;
(semicolons) instead of\n
(carriage returns)
igop repl
A Go+ Read Eval Print Loop
Online: https://repl.goplus.org/
Shebang line:
script.sh
///usr/bin/true; exec /usr/bin/igop run -- "$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.gop --argument1 --argument2]