This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #32 from deta/docs
Update Docs
- Loading branch information
Showing
9 changed files
with
260 additions
and
549 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 |
---|---|---|
@@ -1,61 +1,19 @@ | ||
/* | ||
Package deta is the official Deta SDK for Go | ||
Example: | ||
package main | ||
import ( | ||
"fmt" | ||
"github.com/deta/deta-go/deta" | ||
"github.com/deta/deta-go/service/base" | ||
) | ||
type User struct { | ||
Key string `json:"key"` // json struct tag key to denote the key | ||
Username string `json:"username"` | ||
Email string `json:"email"` | ||
} | ||
func main() { | ||
d, err := deta.New(deta.WithProjectKey("project_key")) | ||
if err != nil { | ||
fmt.Println("failed to init new Deta instance:", err) | ||
return | ||
} | ||
db := base.New(d, "users") | ||
u := &User{ | ||
Key: "abasd", | ||
Username: "jimmy", | ||
Email: "[email protected]", | ||
} | ||
key, err := db.Put(u) | ||
if err != nil { | ||
fmt.Println("failed to put item:", err) | ||
return | ||
} | ||
fmt.Println("successfully put item with key", key) | ||
} | ||
More examples on https://docs.deta.sh/docs/base/sdk | ||
*/ | ||
package deta | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
// Deta is a top-level deta service instance | ||
// Deta is the top-level Deta service instance | ||
type Deta struct { | ||
ProjectKey string | ||
ProjectKey string // deta project key | ||
} | ||
|
||
// ConfigOption is a functional config option for Deta | ||
type ConfigOption func(*Deta) | ||
|
||
// Func returns a function that updates the ProjectKey | ||
// WithProjectKey config option for setting the project key for Deta | ||
func WithProjectKey(projectKey string) ConfigOption { | ||
return func(d *Deta) { | ||
d.ProjectKey = projectKey | ||
|
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 deta is the core Deta SDK package. | ||
Configuring credentials | ||
You will require you project key when using the Deta SDK. | ||
By default, the SDK looks for the environment variable DETA_PROJECT_KEY for the project key. | ||
// Create a new Deta instance taking the project key from the environment by default | ||
d, err := deta.New() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to create new deta instance: %v\n", err) | ||
} | ||
You can use the WithProjectKey option when creating a Deta instance to provide the project key explicitly. | ||
// Create a new Deta instance with explicit project key | ||
d, err := deta.New(deta.WithProjectKey("project_key")) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to create new deta instance: %v\n", err) | ||
} | ||
*/ | ||
package deta |
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,14 @@ | ||
/* | ||
Package sdk is the official Deta SDK for Go. | ||
SDK Packages | ||
The SDK constitutes of two main components, the core package and service packages. | ||
deta - The core SDK package, provides shared functionalities to the service packages. All the errors are also exported from this package. | ||
service - The service packages, the services supported by the SDK. | ||
base - Deta Base service package | ||
drive - Deta Drive service package | ||
*/ | ||
package sdk |
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,73 @@ | ||
/* | ||
Package base is the Deta Base service package. | ||
The following is a simple Put operation example. | ||
import ( | ||
"fmt" | ||
"os" | ||
"github.com/deta/deta-go/deta" | ||
"github.com/deta/deta-go/service/base" | ||
) | ||
// User an example user struct | ||
type User struct { | ||
Key string `json:"key"` // json struct tag 'key' used to denote the key | ||
Username string `json:"username"` | ||
Active bool `json:"active"` | ||
Age int `json:"age"` | ||
Likes []string `json:"likes"` | ||
} | ||
func main() { | ||
// Create a new Deta instance with a project key | ||
d, err := deta.New(deta.WithProjectKey("project_key")) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to create new Deta instance: %v\n", err) | ||
os.Exit(1) | ||
} | ||
// Create a new Base instance called "users", provide the previously created Deta instance | ||
users, err := base.New(d, "users") | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to create new Base instance: %v\n", err) | ||
os.Exit(1) | ||
} | ||
// Put "jimmy" to the "users" Base | ||
key, err := db.Put(&User{ | ||
Key: "jimmy_neutron", | ||
Username: "jimmy", | ||
Active: true, | ||
Age: 20, | ||
Likes: []string{"science"}, | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to put item: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("successfully put item with key %s\n", key) | ||
// A map can also be used | ||
jimmy := map[string]interface{}{ | ||
"key": "jimmy_neutron", | ||
"username": "jimmy", | ||
"active": true, | ||
"age": 20, | ||
"likes": []string{"science"}, | ||
} | ||
key, err = db.Put(jimmy) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to put item: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("successfully put item with key: %s\n", key) | ||
} | ||
More examples and complete documentation on https://docs.deta.sh/docs/base/sdk | ||
*/ | ||
package base |
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,54 @@ | ||
/* | ||
Package drive is the Deta Drive service package. | ||
The following is a simple Put operation example. | ||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"github.com/deta/deta-go/deta" | ||
"github.com/deta/deta-go/service/drive" | ||
) | ||
func main() { | ||
// Create a new Deta instance with a project key | ||
d, err := deta.New(deta.WithProjectKey("project_key")) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to create new Deta instance:%v\n", \n) | ||
os.Exit(1) | ||
} | ||
// Create a new Drive instance called "drawings", provide the previously created Deta instance | ||
drawings, err := drive.New(d, "drawings") | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to create new Drive instance: %v\n", err) | ||
os.Exit(1) | ||
} | ||
// Open local file "art.svg" | ||
file, err := os.Open("./art.svg") | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to open file: %v\n", err) | ||
os.Exit(1) | ||
} | ||
defer file.Close() | ||
// Put "art.svg" to "drawings" | ||
name, err := drawings.Put(&drive.PutInput{ | ||
Name: "art.svg", | ||
Body: bufio.NewReader(file), | ||
ContentType: "image/svg+xml", | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to put file: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("successfully put file %s", name) | ||
} | ||
More examples and complete documentation on https://docs.deta.sh/docs/drive/sdk/ | ||
*/ | ||
package drive |
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