
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
github.com/openengineer/go-repl
Lightweight Golang REPL library, inspired by GNU Readline. You provide the Eval
function, and go-repl
does the rest.
Your REPLs that use this library will enjoy the following features:
Eval
Notes:
Fetch this library with the following command:
$ go get -u github.com/openengineer/go-repl
In order to create your own REPL you have to define a type that implements the Handler
interface:
type Handler interface {
Prompt() string
Tab(buffer string) string
Eval(line string) string
}
Here is a complete example (can also be found in ./examples/basic_repl.go
):
package main
import (
"fmt"
"log"
"strconv"
"strings"
repl "github.com/openengineer/go-repl"
)
var helpMessage = `help display this message
add <int> <int> add two numbers
quit quit this program`
// implements repl.Handler interface
type MyHandler struct {
r *repl.Repl
}
func main() {
fmt.Println("Welcome, type \"help\" for more info")
h := &MyHandler{}
h.r = repl.NewRepl(h)
// start the terminal loop
if err := h.r.Loop(); err != nil {
log.Fatal(err)
}
}
func (h *MyHandler) Prompt() string {
return "> "
}
func (h *MyHandler) Tab(buffer string) string {
return "" // do nothing
}
func (h *MyHandler) Eval(line string) string {
fields := strings.Fields(line)
if len(fields) == 0 {
return ""
} else {
cmd, args := fields[0], fields[1:]
switch cmd {
case "help":
return helpMessage
case "add":
if len(args) != 2 {
return "\"add\" expects 2 args"
} else {
return add(args[0], args[1])
}
case "quit":
h.r.Quit()
return ""
default:
return fmt.Sprintf("unrecognized command \"%s\"", cmd)
}
}
}
func add(a_ string, b_ string) string {
a, err := strconv.Atoi(a_)
if err != nil {
return "first arg is not an integer"
}
b, err := strconv.Atoi(b_)
if err != nil {
return "second arg is not an integer"
}
return strconv.Itoa(a + b)
}
FAQs
Unknown package
Did you know?
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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.