forked from MixinNetwork/ocean.one
-
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.
setup basic spanner as persistence layer
- Loading branch information
1 parent
87f8b48
commit 90c3d18
Showing
7 changed files
with
74 additions
and
8 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
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 |
---|---|---|
@@ -1,8 +1,26 @@ | ||
package main | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
"cloud.google.com/go/spanner" | ||
"github.com/MixinMessenger/ocean.one/config" | ||
"github.com/MixinMessenger/ocean.one/persistence" | ||
) | ||
|
||
func main() { | ||
ex := NewExchange() | ||
ex.Run(context.Background()) | ||
ctx := context.Background() | ||
client, err := spanner.NewClientWithConfig(ctx, config.GoogleCloudSpanner, spanner.ClientConfig{NumChannels: 4, | ||
SessionPoolConfig: spanner.SessionPoolConfig{ | ||
HealthCheckInterval: 5 * time.Second, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Panicln(err) | ||
} | ||
|
||
ctx = persistence.SetupSpanner(ctx, client) | ||
NewExchange().Run(ctx) | ||
} |
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,20 @@ | ||
package persistence | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/MixinMessenger/go-number" | ||
) | ||
|
||
func ReadActionCheckpoint(ctx context.Context) time.Time { | ||
return time.Now() | ||
} | ||
|
||
func CreateOrder(ctx context.Context, userId, traceId string, side, quote, base string, amount, price number.Decimal, createdAt time.Time) error { | ||
return nil | ||
} | ||
|
||
func CancelOrder(ctx context.Context, orderId string, createdAt time.Time) error { | ||
return nil | ||
} |
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,22 @@ | ||
package persistence | ||
|
||
import ( | ||
"context" | ||
|
||
"cloud.google.com/go/spanner" | ||
) | ||
|
||
type contextValueKey int | ||
|
||
const ( | ||
keySpanner contextValueKey = 1 | ||
) | ||
|
||
func SetupSpanner(ctx context.Context, client *spanner.Client) context.Context { | ||
return context.WithValue(ctx, keySpanner, client) | ||
} | ||
|
||
func Spanner(ctx context.Context) *spanner.Client { | ||
v, _ := ctx.Value(keySpanner).(*spanner.Client) | ||
return v | ||
} |
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 @@ | ||
package persistence |
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 @@ | ||
package persistence |