-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from a-company-jp/replace2RealtimeDatabase
Realtime Databaseへの移行
- Loading branch information
Showing
19 changed files
with
415 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: GoTestFirebaseEmulator | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
pull_request: | ||
paths: | ||
- '**.go' | ||
- '.github/**' | ||
jobs: | ||
go-test-with-firebase-emulator: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: ghcr.io/a-company-jp/imagemagick | ||
credentials: | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
permissions: | ||
contents: read | ||
packages: read | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: ./go.mod | ||
cache: true | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '21' | ||
- name: Download Go modules | ||
shell: bash | ||
if: ${{ steps.setup-go.outputs.cache-hit != 'true' }} | ||
run: go mod download | ||
- name: Install firebase-emulator | ||
run: npm install -g firebase-tools | ||
- name: Run Firebase Emulator | ||
run: | | ||
firebase setup:emulators:database | ||
firebase emulators:start --only database & | ||
- name: 'Waiting for the emulator to start up' | ||
run: sleep 20 | ||
- name: Run tests | ||
env: | ||
FIREBASE_DATABASE_EMULATOR_HOST: localhost:9000 | ||
ENV_LOCATION: ${{ github.workspace }}/pkg/config/setting.testing.yaml | ||
run: go test -p=1 -race -coverprofile=coverage.txt -covermode=atomic ./... #gosetup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"rules": { | ||
".read": "now < 1680274800000", | ||
".write": "now < 1680274800000", | ||
"LGTMs": { | ||
".indexOn": [ | ||
"createdAt" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"emulators": { | ||
"database": { | ||
"host": "127.0.0.1", | ||
"port": 9000 | ||
}, | ||
"ui": { | ||
"host": "127.0.0.1", | ||
"enabled": false | ||
}, | ||
"singleProjectMode": true | ||
}, | ||
"database": { | ||
"rules": "database.rules.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
application: | ||
server: | ||
frontend: | ||
protocol: https:// | ||
domain: shion.pro | ||
port: 443 | ||
backend: | ||
protocol: https:// | ||
domain: shion.pro | ||
port: 1305 | ||
gcs: | ||
bucket_name: sample-bucket-name | ||
infrastructure: | ||
google_cloud: | ||
project_id: some-project-id | ||
use_credentials_file: false | ||
credentials_file_path: /dev/null | ||
firebase: | ||
database_url: "http://localhost:9000" | ||
third_party: | ||
service: | ||
authentication: | ||
jwt_secret: "LEN32_AUTH_CIPHER_KEY_TEST_TOKEN" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package fb | ||
|
||
import ( | ||
"context" | ||
firebase "firebase.google.com/go/v4" | ||
"firebase.google.com/go/v4/db" | ||
"fmt" | ||
"google.golang.org/api/option" | ||
"lgtm-gen/pkg/config" | ||
"log" | ||
) | ||
|
||
type Firebase struct { | ||
Client *db.Client | ||
} | ||
|
||
func NewFirebase() (*Firebase, error) { | ||
conf := config.Get() | ||
ctx := context.Background() | ||
|
||
var client *firebase.App | ||
var err error | ||
|
||
fconf := &firebase.Config{ | ||
DatabaseURL: conf.Infrastructure.GoogleCloud.Firebase.DatabaseURL, | ||
} | ||
if conf.Infrastructure.GoogleCloud.UseCredentialsFile { | ||
client, err = firebase.NewApp(ctx, fconf) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create Firestore client without credential: %w", err) | ||
} | ||
} else { | ||
opt := option.WithCredentialsFile( | ||
conf.Infrastructure.GoogleCloud.CredentialsFilePath, | ||
) | ||
client, err = firebase.NewApp(ctx, fconf, opt) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create Firebase client with credential: %w", err) | ||
} | ||
} | ||
|
||
c, err := client.Database(ctx) | ||
if err != nil { | ||
log.Fatalln("Error initializing database client:", err) | ||
} | ||
|
||
return &Firebase{ | ||
Client: c, | ||
}, nil | ||
} | ||
|
||
func NewWithClient(client *db.Client) Firebase { | ||
return Firebase{ | ||
Client: client, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package snowflake | ||
|
||
import ( | ||
"github.com/godruoyi/go-snowflake" | ||
"strconv" | ||
) | ||
|
||
type Snowflake int64 | ||
|
||
func init() { | ||
snowflake.SetMachineID(305) | ||
} | ||
|
||
func NewSnowflake() Snowflake { | ||
return Snowflake(snowflake.ID()) | ||
} | ||
|
||
func (s Snowflake) Int64() int64 { | ||
return int64(s) | ||
} | ||
|
||
func (s Snowflake) String() string { | ||
return strconv.FormatInt(int64(s), 10) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package snowflake | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
const TestSize = 1000000 | ||
|
||
func TestSnowflake(t *testing.T) { | ||
var d = make(map[int64]bool, TestSize) | ||
for i := 0; i < TestSize; i++ { | ||
s := NewSnowflake() | ||
_, has := d[s.Int64()] | ||
if has { | ||
t.Errorf("DUPLICATE DETECTED: %v", s) | ||
} | ||
d[s.Int64()] = true | ||
} | ||
} |
Oops, something went wrong.