Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/shurcooL/goexec

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/shurcooL/goexec

  • v0.0.0-20230709021537-96bada04ea2b
  • Source
  • Go
  • Socket score

Version published
Created
Source

goexec

Go Reference

goexec is a command line tool to execute Go code. Output is printed as goons to stdout.

Installation

go install github.com/shurcooL/goexec@latest

Usage

Usage: goexec [flags] [packages] [package.]function(parameters)
       echo parameters | goexec -stdin [flags] [packages] [package.]function
  -compiler string
    	Compiler to use, one of: "gc", "gopherjs". (default "gc")
  -n	Print the generated source but do not run it.
  -quiet
    	Do not dump the return values as a goon.
  -stdin
    	Read func parameters from stdin instead.
  -tags string
    	A comma-separated list of build tags to consider satisfied during the build.

Examples

$ goexec 'strings.Repeat("Go! ", 5)'
(string)("Go! Go! Go! Go! Go! ")

$ goexec strings 'Replace("Calling Go functions from the terminal is hard.", "hard", "easy", -1)'
(string)("Calling Go functions from the terminal is easy.")

# Note that parser.ParseExpr returns 2 values (ast.Expr, error).
$ goexec 'parser.ParseExpr("5 + 7")'
(*ast.BinaryExpr)(&ast.BinaryExpr{
	X: (*ast.BasicLit)(&ast.BasicLit{
		ValuePos: (token.Pos)(1),
		Kind:     (token.Token)(5),
		Value:    (string)("5"),
	}),
	OpPos: (token.Pos)(3),
	Op:    (token.Token)(12),
	Y: (*ast.BasicLit)(&ast.BasicLit{
		ValuePos: (token.Pos)(5),
		Kind:     (token.Token)(5),
		Value:    (string)("7"),
	}),
})
(interface{})(nil)

# Run function RepoRootForImportPath from package "golang.org/x/tools/go/vcs".
$ goexec 'vcs.RepoRootForImportPath("rsc.io/pdf", false)'
(*vcs.RepoRoot)(...)
(interface{})(nil)

$ goexec -quiet 'fmt.Println("Use -quiet to disable output of goon; useful if you want to print to stdout.")'
Use -quiet to disable output of goon; useful if you want to print to stdout.

$ echo '"fmt"' | goexec -stdin 'gist4727543.GetForcedUse'
(string)("var _ = fmt.Errorf")

Alternatives

  • gommand - Go one liner program, similar to python -c.
  • gorram - Like go run for any Go function.
  • goeval - Run Go snippets instantly from the command-line.

License

FAQs

Package last updated on 09 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc