docker - 使用docker安装go的应用程序时如何解决“未定义:math.Round”的问题
问题描述
我制作了 golang api 的代码,并在其中导入了一些包,例如math
. 但是在通过sudo docker build -t users/micro .
一步运行 Then 来构建图像时,它会给我错误。
错误
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 }
我将如何解决我的错误
解决方案
Round()
包中的功能math
仅在 Go 1.10 中引入(请参阅发行说明)。您的 Dockerfile 使用较旧的 1.9.6 版本,因此您必须升级。
推荐阅读
- python - 如何从python列表中删除停用词
- android - 使用 Amazon Cognito 的推荐邀请
- node.js - 如何将函数存储在 MongoDb 文档中,然后从那里读取并调用它?
- gimp - 像素区域比较
- spring - 值未显示到 Spring MVC 视图中
- javascript - 如何从另一个父道具获得道具?
- java - 升级 Java 和 Eclipse 版本
- c++ - 为什么该文件中的数据没有正确写入/读取?
- javascript - jQuery 库与内联脚本冲突
- javascript - NodeJS Express - GET/POST/PATCH/DELETE 在幕后的区别