GolangTraining
GolangTraining copied to clipboard
How to use the REPL mode in the Golang language
How to use the REPL mode in the Golang language
You should look at this repo -> https://github.com/golobby/repl
@ghost @eyupfidan Here is one small example of repl, this is inside main package, you can also create a separate package for repl
`package main
import ( "bufio" "fmt" "io" "os" )
const PROMPT = ">> "
func main() { fmt.Println("Hello bajrang") Start(os.Stdin, os.Stdout) }
func Start(in io.Reader, out io.Writer) { scanner := bufio.NewScanner(in) for { fmt.Printf(PROMPT) scanned := scanner.Scan() if !scanned { return } line := scanner.Text() fmt.Println("line = ", line) } } `