Hello everyone i am trying to learn how to wait for user input with golang cli app in docker, her is my main.go file
package main
import (
"bufio"
"fmt"
"os"
"strings"
"strconv"
)
func main(){
reader := bufio.NewReader(os.Stdin)
var errConv error
for {
fmt.Print("-> ")
inputText, _ := reader.ReadBytes('\n')
// Receive input
text := string(inputText)
var command []string
for _, word := range strings.Fields(text) {
command = append(command,word)
}
if command[0] == "create_day_max"{
//do something
}
}
}
this is my Dockerfile
# Start from golang base image
FROM golang:1.15.2
# Copy the source from the current directory to the working Directory inside the container
COPY . /usr/src/golang-tunaiku
# Move to working directory
WORKDIR /usr/src/golang-tunaiku
#install depedencies
RUN go mod download
# Build the application
RUN go build -o golang-tunaiku
#Command to run the executable
CMD [ "./golang-tunaiku" ]
and this is my docker-compose.yml file
version: '3'
services:
app:
container_name: golang-linkaja
build: .
it run fine when i do go run main.go but when i use docker-compose up --build
, it just does not wait for user input, thus it create error like this
-> panic: runtime error: index out of range
which is obvious since it is forcing to read index 0 while there is no user input, How do i wait for user input on golang clip app with docker compose? Thanks in advance i am stil learning