百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gore

> 编程语言
开源

用于 Go 代码的评估器

193 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于 Go 代码的评估器

#gore

gore is a command-line evaluator for golang code -- a REPL without a loop, if you will. It is a replacement for the go playground, while making it much easier to interactively try out bits of code: gore automatically supplies boiler-plate code such as import and package declarations and a main function wrapper. Also, since it runs on your own computer, no code is rejected on security grounds (unlike go playground's safe sandbox mode).

#Usage

(note: In the examples below, $ is the shell prompt, and the output of the snippet follows "----------------"

Code snippet in command line: gore evaluates its first argument

$ gore 'println(200*300, math.Log10(1000))'
---------------------------------
60000 +3.000000e+000

Note the absence of boiler-plate code like package main, import "math" and func main() {}

Default to stdin without arguments

$ gore
Enter one or more lines and hit ctrl-D
func test() string {return "hello"}
println(test())
^D
---------------------------------
hello

Alias for convenient printing

The example above can be written more compactly:

$ gore 'p 200*300, math.Log10(100)'
---------------------------------
60000
2

p arg1, arg2 pretty-prints each argument by formatting it with fmt.Printf("%v\n") t arg1, arg2` prints the type of each argument

Command-line arg can be over multiple lines

$ gore '
 p "Making a point"
 type Point struct {
    x,y int
 }
 v := Point{10, 100}
 p v
' 
---------------------------------
Making a point
{10 100}

Import statements are inferred

Standard go packages are automatically imported. Where there is a clash of names, the more "likely" one is preferred: math/rand to crypto/rand, net/http/pprof to runtime/pprof and text/template to html/template. Of course, you can add import statements of your own (which overrides the default preferences as well)

$ gore '
  r := regexp.MustCompile(`(\w+) says (\w+)`)
  match := r.FindStringSubmatch("World says Hello")
  p "0:" + match[0], "1:"+ match[1], "2:" + match[2]
  '
---------------------------------
0:World says Hello
1:World
2:Hello

Install

go get github.com/sriram-srinivasan/gore
go test github.com/sriram-srinivasan/gore/eval

The gore/eval package

gore is a thin command-line wrapper over the gore/eval package. Use this for your own REPL.

How it works

The eval.Eval function expands aliases, and scans the snippet for references to packages from the standard Go library. All such references a corresponding import statement. The source is then partitioned into global and non-global code, where global refers to type, import and func declarations. The rest is bundled into a func main() {} wrapper. This reorganized code is compiled using go run and the output (stdout and stderr) collected. If there are compiler errors pointing to incorrectly inferred packages, the corresponding import statements are removed and the code is run once again.

To examine the generated code, set the environment variables TMPDIR or TEMPDIR, and look for $TMPDIR/gore_eval.go

License

gore is available under a liberal MIT style license. See the LICENSE file.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Go

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言