Как решить проблему «undefined: math.Round» при установке приложения go с помощью Docker - PullRequest
0 голосов
/ 01 октября 2018

Я создаю код golang api и импортировал в него несколько пакетов, например math.Но при создании образа с помощью sudo docker build -t users/micro . Затем на одном шаге он выдаст ошибку.

Ошибка

 Step 6/8 : RUN go install
 ---> Running in 454784b3ceef
 # bkapiv/users/utils
 utils/CommonFunctions.go:189:9: undefined: math.Round

Dockerfile

# Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang:1.9.6


WORKDIR /go/src/bkapiv/users

# Copy the local package files to the container's workspace.
ADD . /go/src/bkapiv/users

# Build the outyet command inside the container.
# (You may fetch or manage dependencies here,
# either manually or with a tool like "godep".)
RUN cd /go/src
RUN go-wrapper download   # "go get -d -v ./..."
RUN go install

# Run the outyet command by default when the container starts.
ENTRYPOINT /go/bin/users

# Document that the service listens on port 8080.
EXPOSE 8080

Импортированные пакеты

package utils

import (
 "bytes"
 "fmt"
 "math"
 "math/rand"
 "os/exec"
 "reflect"
 "sort"
 "strconv"
 "time"
)

 187 func Round(x, unit float64) float64 {
 188        // for this line it will giving me the error 
 189    return math.Round(x/unit) * unit
 190 }

Как я исправлю свою ошибку

1 Ответ

0 голосов
/ 01 октября 2018

Функция Round() из пакета math была представлена ​​только в Go 1.10 ( см. Примечания к выпуску ).Ваш Dockerfile использует более старую версию 1.9.6, поэтому вам придется обновить.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...