GolangTraining icon indicating copy to clipboard operation
GolangTraining copied to clipboard

How to use the REPL mode in the Golang language

Open ghost opened this issue 3 years ago • 2 comments

How to use the REPL mode in the Golang language

ghost avatar Apr 30 '22 01:04 ghost

You should look at this repo -> https://github.com/golobby/repl

eyupfidan avatar Aug 19 '22 13:08 eyupfidan

@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) } } `

parit90 avatar Sep 10 '22 00:09 parit90