mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-23 18:17:32 +00:00
Remove session after rejoin few times
This commit is contained in:
parent
485b30389d
commit
401940b717
9 changed files with 105 additions and 20 deletions
55
handler/cloud-storage/storage.go
Normal file
55
handler/cloud-storage/storage.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"cloud.google.com/go/storage"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
bucket string
|
||||
gclient storage.Client
|
||||
}
|
||||
|
||||
func NewClient() *Client {
|
||||
ctx := context.Background()
|
||||
|
||||
// Sets your Google Cloud Platform project ID.
|
||||
projectID := "YOUR_PROJECT_ID"
|
||||
|
||||
// Creates a client.
|
||||
client, err := storage.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create client: %v", err)
|
||||
}
|
||||
|
||||
// Sets the name for the new bucket.
|
||||
bucketName := "my-new-bucket"
|
||||
|
||||
// Creates a Bucket instance.
|
||||
bucket := client.Bucket(bucketName)
|
||||
|
||||
// Creates the new bucket.
|
||||
if err := bucket.Create(ctx, projectID, nil); err != nil {
|
||||
log.Fatalf("Failed to create bucket: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Bucket %v created.\n", bucketName)
|
||||
}
|
||||
|
||||
func (c *Client) SaveFile(name string, data string) (err error) {
|
||||
wc := c.gclient.Bucket(c.bucket).Object(name).NewWriter(nil)
|
||||
if _, err = io.Copy(wc, f); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := wc.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Helper) LoadFile(name string) []byte {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue