gore

package module
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2025 License: MIT Imports: 36 Imported by: 2

README

gore

CI Status MIT License release

Screencast

(Screencast taken with cho45/KeyCast)

Usage

gore

After a prompt is shown, enter any Go expressions/statements/functions or commands described below.

To quit the session, type Ctrl-D or use :q command.

Features

  • Line editing with history
  • Multi-line input
  • Package importing with completion
  • Evaluates any expressions, statements and function declarations
  • No "evaluated but not used" errors
  • Code completion (requires gopls)
  • Showing documents
  • Auto-importing (gore -autoimport)

REPL Commands

Some functionalities are provided as commands in the REPL:

:import <package path>  Import package
:type <expr>            Print the type of expression
:print                  Show current source
:write [<filename>]     Write out current source to file
:clear                  Clear the codes
:doc <expr or pkg>      Show document
:help                   List commands
:quit                   Quit the session

Installation

The gore command requires Go tool-chains on runtime, so standalone binary is not distributed.

go install github.com/x-motemen/gore/cmd/gore@latest

Make sure $GOPATH/bin is in your $PATH.

Also recommended:

go install golang.org/x/tools/gopls@latest   # for code completion

Or you can use Docker:

docker run -it --rm ghcr.io/x-motemen/gore

FAQ/Caveats

  • gore runs code using go run for each input. Every line entered is evaluated repeatedly (#67), so you can't bind the evaluated time by time.Now(), for example. This implementation also makes the execution fairly slow (#182). This project started from a simple idea to use go run for all REPL input. I think this project has provided some value for Go users, but these days there are other REPL implementations that are more actively maintained and run faster. I recommend using gomacro or yaegi.
  • gore support Go modules. You can load local modules when you start gore at the project directory. You don't need to go get to check the usage of a remote repository, :import github.com/... will automatically download that module. Also, you don't need to go get the pretty print module anymore. If you want to load a local code from $GOPATH, you need to create the modules file (go mod init ...) and then start gore at the project directory.

License

The MIT License.

Author

Documentation

Index

Constants

View Source
const Version = "0.6.1"

Version of gore.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error ...

const (
	ErrContinue Error = "<continue input>"
	ErrQuit     Error = "<quit session>"
	ErrCmdRun   Error = "<command failed>"
)

Errors

func (Error) Error

func (e Error) Error() string

type Gore added in v0.4.1

type Gore struct {
	// contains filtered or unexported fields
}

Gore ...

func New added in v0.4.1

func New(opts ...Option) *Gore

New Gore

func (*Gore) Run added in v0.4.1

func (g *Gore) Run() error

Run ...

type Option added in v0.4.1

type Option func(*Gore)

Option for Gore

func AutoImport added in v0.4.1

func AutoImport(autoImport bool) Option

AutoImport option

func ErrWriter added in v0.4.1

func ErrWriter(errWriter io.Writer) Option

ErrWriter option

func ExtFiles added in v0.4.1

func ExtFiles(extFiles string) Option

ExtFiles option

func OutWriter added in v0.4.1

func OutWriter(outWriter io.Writer) Option

OutWriter option

func PackageName added in v0.4.1

func PackageName(packageName string) Option

PackageName option

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session ...

func NewSession

func NewSession(stdout, stderr io.Writer) (*Session, error)

NewSession creates a new Session.

func (*Session) Clear

func (s *Session) Clear() error

Clear the temporary directory.

func (*Session) Eval

func (s *Session) Eval(in string) error

Eval the input.

func (*Session) Run

func (s *Session) Run() error

Run the session.

Directories

Path Synopsis
cmd
gore command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL