
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.