• Stars
    star
    374
  • Rank 114,335 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 11 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A command line tool to execute Go functions.

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

More Repositories

1

githubv4

Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql).
Go
1,118
star
2

vfsgen

Takes an input http.FileSystem (likely at go generate time) and generates Go code that statically implements it.
Go
982
star
3

Go-Package-Store

An app that displays updates for the Go packages in your GOPATH.
Go
899
star
4

markdownfmt

Like gofmt, but for Markdown.
Go
796
star
5

graphql

Package graphql provides a GraphQL client implementation.
Go
702
star
6

gostatus

A command line tool that shows the status of Go repositories.
Go
244
star
7

github_flavored_markdown

GitHub Flavored Markdown renderer with fenced code block highlighting, clickable header anchor links.
Go
159
star
8

binstale

binstale tells you whether the binaries in your GOPATH/bin are stale or up to date.
Go
146
star
9

go

Common Go code.
Go
127
star
10

home

home is Dmitri Shuralyov's personal website.
Go
76
star
11

httpfs

Collection of Go packages for working with the http.FileSystem interface.
Go
62
star
12

Hover

A work-in-progress source port of Hover.
C++
59
star
13

eX0

Unfinished multiplayer tactical 2D shooter indie game.
C++
50
star
14

git-branches

git-branches prints the commit behind/ahead counts for branches.
Go
42
star
15

play

Short experimental programs for playing with and learning new things. No importable Go packages here.
JavaScript
38
star
16

gtdo

The source for gotools.org.
Go
36
star
17

tictactoe

Package tictactoe defines the game of tic-tac-toe.
Go
31
star
18

sanitized_anchor_name

Package sanitized_anchor_name provides a func to create sanitized anchor names.
Go
27
star
19

httpgzip

Package httpgzip provides net/http-like primitives that use gzip compression when serving HTTP requests.
Go
24
star
20

issuesapp

Package issuesapp is a web frontend for an issues service.
Go
23
star
21

godecl

A godecl experiment. Like cdecl, but for Go.
Go
20
star
22

cmd

Various small command-line utilities.
Go
18
star
23

frontend

Common frontend code.
HTML
13
star
24

notifications

Package notifications provides a notifications service definition.
Go
11
star
25

issues

Package issues provides an issues service definition.
Go
11
star
26

resume

resume is Dmitri Shuralyov's résumé.
Go
9
star
27

highlight_go

Syntax highlighter for Go, using go/scanner.
Go
8
star
28

octicon

Package octicon provides GitHub Octicons.
Go
8
star
29

webdavfs

Collection of Go packages for working with the webdav.FileSystem interface.
Go
8
star
30

notificationsapp

Package notificationsapp is a web frontend for a notifications service.
Go
8
star
31

events

Package events provides an events service definition.
Go
7
star
32

ivybrowser

A port of Rob Pike's ivy that runs in the browser.
Go
7
star
33

SLA

Service-level agreement for Go packages.
6
star
34

gofontwoff

Package gofontwoff provides the Go font family in Web Open Font Format.
CSS
5
star
35

vcsstate

Package vcsstate allows getting the state of version control system repositories.
Go
5
star
36

htmlg

Package for generating and rendering HTML nodes with context-aware escaping.
Go
5
star
37

reactions

Package reactions provides a reactions service definition.
HTML
3
star
38

highlight_diff

Syntax highlighter for diff format, with inner diff highlighting.
Go
2
star
39

users

Package users provides a users service definition.
Go
2
star
40

httperror

Package httperror provides common basic building blocks for custom HTTP frameworks.
Go
1
star