{"id":13720830,"url":"https://github.com/deta/deta-go","last_synced_at":"2025-05-07T13:30:36.807Z","repository":{"id":43465292,"uuid":"309334368","full_name":"deta/deta-go","owner":"deta","description":"Deta Golang SDK","archived":false,"fork":false,"pushed_at":"2023-07-13T18:52:34.000Z","size":83,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-04T01:14:00.524Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.deta.sh/docs/base/sdk","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-11-02T10:24:15.000Z","updated_at":"2023-09-08T18:14:24.000Z","dependencies_parsed_at":"2024-01-06T01:03:37.947Z","dependency_job_id":"3b718392-899f-4a14-b4bf-50a5eb824f69","html_url":"https://github.com/deta/deta-go","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deta%2Fdeta-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deta%2Fdeta-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deta%2Fdeta-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deta%2Fdeta-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deta","download_url":"https://codeload.github.com/deta/deta-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224604586,"owners_count":17339166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:01:08.542Z","updated_at":"2024-11-14T10:30:36.252Z","avatar_url":"https://github.com/deta.png","language":"Go","readme":"# DETA SDK for Go\n\n[![Go Doc](https://img.shields.io/badge/go-doc-blue)](https://godoc.org/github.com/deta/deta-go)\n\ndeta-go is the official Deta SDK for Go. \n\n## Installing\n\nUse `go get` to retreive the SDK to add it to your `GOPATH` workspace, or project's Go module dependencies.\n\n```\ngo get github.com/deta/deta-go\n```\n\nTo update the SDK use `go get -u` to retrieve the latest version of the SDK.\n\n```\ngo get -u github.com/deta/deta-go\n```\n\nIf you are using Go modules, your `go get` will default to the latest tagged release version of the SDK. To get a specific release version of the SDK use `@\u003ctag\u003e` in your `go get` command.\n\n```\ngo get github.com/deta/deta-go@v1.0.0\n```\n\nTo get the latest SDK repository change use `@latest`.\n```\ngo get github.com/aws/deta-go@latest\n```\n\n### SDK Packages\n\nThe SDK constitutes of two main components, the core package and service packages.\n\n- `deta`: The core SDK package, provides shared functionalities to the service packages. All the `errors` are also exported from this package.\n\n- `service`: The service packages, the services supported by the SDK.\n\t- `base`: Deta Base service package\n\t- `drive`: Deta Drive service package\n\n### Configuring credentials\n\nWhen using the SDK you will require you project key. The project key can be provided explicitly or is taken from the environement variable `DETA_PROJECT_KEY`.\n\n#### Default\n\nBy default, the SDK looks for the environment variable `DETA_PROJECT_KEY` for the project key\n\n```go\n// Create a new Deta instance taking the project key from the environment by default\nd, err := deta.New()\nif err != nil {\n\tfmt.Fprintf(os.Stderr, \"failed to create new deta instance: %v\\n\", err)\n}\n```\n\n#### Provide the project key explicitly\n\nYou can use the `WithProjectKey` option when creating a `Deta` instance to provide the project key explicitly. \n\n```go\n// Create a new Deta instance with explicit project key\nd, err := deta.New(deta.WithProjectKey(\"project_key\"))\nif err != nil {\n\tfmt.Fprintf(os.Stderr, \"failed to create new deta instance: %v\\n\", err)\n}\n```\n\n\n## Examples\n\n### Base\n\nThe following is a simple `Put` operation example.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/deta/deta-go/deta\"\n\t\"github.com/deta/deta-go/service/base\"\n)\n\n// User an example user struct\ntype User struct {\n\t// json struct tag 'key' used to denote the key\n\tKey      string   `json:\"key\"` \n\tUsername string   `json:\"username\"`\n\tActive   bool     `json:\"active\"`\n\tAge      int      `json:\"age\"`\n\tLikes    []string `json:\"likes\"`\n\t// json struct tag '__expires' for expiration timestamp\n\t// 'omitempty' to prevent default 0 value\n\tExpires  int64    `json:\"__expires,omitempty\"`\n}\n\nfunc main() {\n\t// Create a new Deta instance with a project key\n\td, err := deta.New(deta.WithProjectKey(\"project_key\"))\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to create new Deta instance: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// Create a new Base instance called \"users\", provide the previously created Deta instance \n\tusers, err := base.New(d, \"users\")\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to create new Base instance: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// Put \"jimmy\" to the \"users\" Base\n\tkey, err := users.Put(\u0026User{\n\t\tKey: \"jimmy_neutron\", \n\t\tUsername: \"jimmy\",\n\t\tActive: true,\n\t\tAge: 20,\n\t\tLikes: []string{\"science\"},\n\t})\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to put item: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(\"successfully put item with key %s\\n\", key)\n\n\t// A map can also be used\n\tjimmy := map[string]interface{}{\n\t\t\"key\":      \"jimmy_neutron\",\n\t\t\"username\": \"jimmy\",\n\t\t\"active\":   true,\n\t\t\"age\":      20,\n\t\t\"likes\":    []string{\"science\"},\n\t}\n\tkey, err = users.Put(jimmy)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to put item: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(\"successfully put item with key: %s\\n\", key)\n\n\t// Put with expiration timestamp\n\teu := \u0026User{\n\t\tKey: \"tmp_user_key\",\n\t\tUsername: \"test_user\",\n\t\tExpires: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),\n\t}\n\tkey, err = users.Put(eu)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to put item: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(\"successfully put expiring item with key: %s\\n\", key)\n\n\t// Put map with expiration timestamp\n\ttmp := map[string]interface{}{\n\t\t\"key\": \"tmp_user_key\",\n\t\t\"username\": \"test_user\",\n\t\t// use `__expires` as the key for expiration timestamp\n\t\t\"__expires\": time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),\n\t}\n\tkey, err = users.Put(tmp)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to put item: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(\"successfully put expiring item with key: %s\\n\", key)\n}\n```\n\nMore examples and complete documentation on https://docs.deta.sh/docs/base/sdk\n\n### Drive\n\nThe following is a simple `Put` operation example.\n\n```go\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/deta/deta-go/deta\"\n\t\"github.com/deta/deta-go/service/drive\"\n)\n\nfunc main() {\n\t// Create a new Deta instance with a project key\n\td, err := deta.New(deta.WithProjectKey(\"project_key\"))\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to create new Deta instance:%v\\n\", \\n)\n\t\tos.Exit(1)\n\t}\n\n\t// Create a new Drive instance called \"drawings\", provide the previously created Deta instance\n\tdrawings, err := drive.New(d, \"drawings\")\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to create new Drive instance: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// Open local file \"art.svg\"\n\tfile, err := os.Open(\"./art.svg\")\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to open file: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tdefer file.Close()\n\n\t// Put \"art.svg\" to \"drawings\"\n\tname, err := drawings.Put(\u0026drive.PutInput{\n\t\tName:        \"art.svg\",\n\t\tBody:        bufio.NewReader(file),\n\t\tContentType: \"image/svg+xml\",\n\t})\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"failed to put file: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(\"successfully put file %s\", name)\n}\n```\n\nMore examples and complete documentation on https://docs.deta.sh/docs/drive/sdk/\n\n","funding_links":[],"categories":["SDK's"],"sub_categories":["Go SDK"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeta%2Fdeta-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeta%2Fdeta-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeta%2Fdeta-go/lists"}