From 59c47aeab18f714f485b4c731b2f1ae2a3389637 Mon Sep 17 00:00:00 2001 From: Yoshiyuki Mineo Date: Mon, 5 May 2025 19:51:28 +0900 Subject: [PATCH] Fix lint errors (#70) --- .github/workflows/test-v1.yml | 8 +++++--- .github/workflows/test-v2.yml | 6 ++++-- .gitignore | 2 ++ example/Dockerfile | 7 +++++-- example/README.md | 18 ++++++++---------- mock/{sonyflake_mock.go => mock.go} | 0 v2/example/Dockerfile | 7 +++++-- v2/example/README.md | 18 ++++++++---------- v2/mock/{sonyflake_mock.go => mock.go} | 0 v2/sonyflake.go | 1 + 10 files changed, 38 insertions(+), 29 deletions(-) rename mock/{sonyflake_mock.go => mock.go} (100%) rename v2/mock/{sonyflake_mock.go => mock.go} (100%) diff --git a/.github/workflows/test-v1.yml b/.github/workflows/test-v1.yml index 22cc0fe..aebfd59 100644 --- a/.github/workflows/test-v1.yml +++ b/.github/workflows/test-v1.yml @@ -5,12 +5,14 @@ on: paths-ignore: - README.md - .github/workflows/test-v2.yml - - 'v2/**' + - v2/** pull_request: paths-ignore: - README.md - .github/workflows/test-v2.yml - - 'v2/**' + - v2/** + +permissions: read-all jobs: test-v1: @@ -30,7 +32,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: ${{matrix.go-version}} diff --git a/.github/workflows/test-v2.yml b/.github/workflows/test-v2.yml index e257ee3..707e7e5 100644 --- a/.github/workflows/test-v2.yml +++ b/.github/workflows/test-v2.yml @@ -5,12 +5,14 @@ on: paths: - README.md - .github/workflows/test-v2.yml - - 'v2/**' + - v2/** pull_request: paths: - README.md - .github/workflows/test-v2.yml - - 'v2/**' + - v2/** + +permissions: read-all jobs: test-v2: diff --git a/.gitignore b/.gitignore index 4fcc071..5c86591 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +example/example example/sonyflake_server +v2/example/example v2/example/sonyflake_server diff --git a/example/Dockerfile b/example/Dockerfile index 6344389..ca565b7 100644 --- a/example/Dockerfile +++ b/example/Dockerfile @@ -1,6 +1,9 @@ FROM ubuntu:14.04 -ADD ./sonyflake_server / -ENTRYPOINT ["/sonyflake_server"] +COPY ./sonyflake_server /sonyflake_server +RUN useradd -m sonyflake +USER sonyflake + +ENTRYPOINT ["/sonyflake_server"] EXPOSE 8080 diff --git a/example/README.md b/example/README.md index 17fbcab..d9a21a5 100644 --- a/example/README.md +++ b/example/README.md @@ -1,21 +1,19 @@ -Example -======= +# Example This example runs Sonyflake on AWS Elastic Beanstalk. -Setup ------ +## Setup 1. Build the cross compiler for linux/amd64 if using other platforms. - ``` - cd $GOROOT/src && GOOS=linux GOARCH=amd64 ./make.bash - ``` + ```bash + cd $GOROOT/src && GOOS=linux GOARCH=amd64 ./make.bash + ``` 2. Build sonyflake_server in the example directory. - ``` - ./linux64_build.sh - ``` + ```bash + ./linux64_build.sh + ``` 3. Upload the example directory to AWS Elastic Beanstalk. diff --git a/mock/sonyflake_mock.go b/mock/mock.go similarity index 100% rename from mock/sonyflake_mock.go rename to mock/mock.go diff --git a/v2/example/Dockerfile b/v2/example/Dockerfile index 4ac65f6..91591ca 100644 --- a/v2/example/Dockerfile +++ b/v2/example/Dockerfile @@ -1,6 +1,9 @@ FROM ubuntu:24.04 -ADD ./sonyflake_server / -ENTRYPOINT ["/sonyflake_server"] +COPY ./sonyflake_server /sonyflake_server +RUN useradd -m sonyflake +USER sonyflake + +ENTRYPOINT ["/sonyflake_server"] EXPOSE 8080 diff --git a/v2/example/README.md b/v2/example/README.md index 17fbcab..d9a21a5 100644 --- a/v2/example/README.md +++ b/v2/example/README.md @@ -1,21 +1,19 @@ -Example -======= +# Example This example runs Sonyflake on AWS Elastic Beanstalk. -Setup ------ +## Setup 1. Build the cross compiler for linux/amd64 if using other platforms. - ``` - cd $GOROOT/src && GOOS=linux GOARCH=amd64 ./make.bash - ``` + ```bash + cd $GOROOT/src && GOOS=linux GOARCH=amd64 ./make.bash + ``` 2. Build sonyflake_server in the example directory. - ``` - ./linux64_build.sh - ``` + ```bash + ./linux64_build.sh + ``` 3. Upload the example directory to AWS Elastic Beanstalk. diff --git a/v2/mock/sonyflake_mock.go b/v2/mock/mock.go similarity index 100% rename from v2/mock/sonyflake_mock.go rename to v2/mock/mock.go diff --git a/v2/sonyflake.go b/v2/sonyflake.go index 870c822..e6ab73a 100644 --- a/v2/sonyflake.go +++ b/v2/sonyflake.go @@ -247,6 +247,7 @@ func lower16BitPrivateIP(interfaceAddrs types.InterfaceAddrs) (int, error) { return int(ip[2])<<8 + int(ip[3]), nil } +// ToTime returns the time when the given ID was generated. func (sf *Sonyflake) ToTime(id int64) time.Time { return time.Unix(0, (sf.startTime+sf.timePart(id))*sf.timeUnit) }