Skip to content
/ gos Public

Run Go scripts instantly with this tiny Golang interpreter—no Go compiler required, just 19MB!

Notifications You must be signed in to change notification settings

go-mixed/gos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gos

Golang/Go+ interpreter. Base on igop v0.27.1

✨ Feature highlights

  • Run the Golang WITHOUT Golang compiler(150MB+)

  • Only 14MB after built and UPX -9

  • Go+ script file,

  • Golang file

  • Golang project

  • Golang project in an archive file of *.tar.gz, *.tar.xz, ...

  • Support shebang line, like #!/usr/bin/bash

  • Go1.18~1.22 generics

  • main.go in the subdirectory

  • *.asm file support

TOC

⌛ Run Golang files

gos <PATH>
  [-V | --debug]
  -- <arguments>

Run a Go+ script, or a Golang project

Type Default
<PATH> String File of Golang+ script, "*.gop".
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 plugin

    gos run . --plugin /path/to/plugin1.so --plugin /path/to/plugin2.so

    See https://github.com/go-mixed/gops_plugins

Single file mode

Run a file with *.gop*.go

.go must be package main and includes func main()

See examples/example2/1.goexamples/example2/2.go

Run

gos /path/to/file.gop

Run in the working directory

cd /path/to
gos file.gop

With arguments

gos file.gop -- --abc 123 --def

Project mode

1. Simple and flattened project

  • Must be package main and One func main() in the working directory
  • The gop file implicitly contains a func main(), which is why only one gop file is allowed.
/path/to/
 - func.go
 - func.gop
 - main.go

See examples/example3

Run

gos /path/to/examples/example3

Run in the working directory

cd /path/to/examples/example3
gos .

With arguments

gos . -- --abc 123 --def

2. Project with submodules, or 3rd party modules.

  • No allowed *.gop
  • go.mod MUST be in the working directory
  • vendor/modules.txt MUST 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

See examples/example1/

Archive mode

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

See examples/example5.tar.gz

Run an archive

gos examples/example5.tar.gz

With arguments

gos examples2/2.go -- --abc 123 --def

⚡ Execute code

gos
  [-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.

Example

Code from StdIn

gos < example2/1.gop
cat example2/1.gop | gos
echo "i := 1+2; println(i)" | gos
printf "i := 1+2 \n println(i)" | gos

Code in argument "-s"

$ gos -s "i := 1+2; println(i)"

Use ;(semicolons) instead of carriage returns

REPL

gos repl

A Go+ Read Eval Print Loop

Online: https://repl.goplus.org/

Run as shell file, like "*.sh"

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

Print

[./script.sh.gop --argument1 --argument2]

Development

Install dependencies

go install github.com/goplus/igop/cmd/qexp@latest

Build build-in scripts

cd pkgs
qexp -outdir . -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

cd ..
go build

About

Run Go scripts instantly with this tiny Golang interpreter—no Go compiler required, just 19MB!

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages