分类 go 下的文章

Go 项目拉取依赖速度慢

export GOPROXY=https://goproxy.cn,direct
export GOPRIVATE=git.mycompany.com,github.com/my/private

Python 项目拉取依赖速度慢

~/.pip/pip.conf文件:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

Node.js 项目拉取依赖速度慢

npm i --registry=https://registry.npmmirror.com --disturl=https://npmmirror.com/dist

Maven 项目拉取依赖速度慢

settings.xml文件:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>*</mirrorOf>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
  </mirrors>
</settings>

# Building the binary of the App
FROM golang:1.19 AS build

# `boilerplate` should be replaced with your project name
WORKDIR /go/src/boilerplate

# Copy all the Code and stuff to compile everything
COPY . .

# Downloads all the dependencies in advance (could be left out, but it's more clear this way)
RUN go mod download

# Builds the application as a staticly linked one, to allow it to run on alpine
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app .


# Moving the binary to the 'final Image' to make it smaller
FROM alpine:latest as release

WORKDIR /app

# Create the `public` dir and copy all the assets into it
RUN mkdir ./static
COPY ./static ./static

# `boilerplate` should be replaced here as well
COPY --from=build /go/src/boilerplate/app .

# Add packages
RUN apk -U upgrade \
    && apk add --no-cache dumb-init ca-certificates \
    && chmod +x /app/app

# Exposes port 3000 because our program listens on that port
EXPOSE 3000

ENTRYPOINT ["/usr/bin/dumb-init", "--", "sh", "-c", "/app/app"]

Installation

tar -C /usr/local -xzf go1.21.4.linux-amd64.tar.gz
vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
source /etc/profile

设置GoProxy

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct