Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the REPL mode in the Golang language #59

Open
ghost opened this issue Apr 30, 2022 · 2 comments
Open

How to use the REPL mode in the Golang language #59

ghost opened this issue Apr 30, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 30, 2022

How to use the REPL mode in the Golang language

@eyupfidan
Copy link

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

@parit90
Copy link

parit90 commented Sep 10, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants