{"id":21178678,"url":"https://github.com/poabob/go-discord","last_synced_at":"2025-03-14T18:43:24.431Z","repository":{"id":204261673,"uuid":"711452599","full_name":"POABOB/go-discord","owner":"POABOB","description":"A discord clone built with Golang.","archived":false,"fork":false,"pushed_at":"2023-11-26T09:03:02.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T11:45:14.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/POABOB.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-29T10:10:21.000Z","updated_at":"2023-10-29T10:15:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"0b78ab15-de89-4f17-a1d9-92871536f33a","html_url":"https://github.com/POABOB/go-discord","commit_stats":null,"previous_names":["poabob/go-discord"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fgo-discord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fgo-discord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fgo-discord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fgo-discord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/POABOB","download_url":"https://codeload.github.com/POABOB/go-discord/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243629222,"owners_count":20322017,"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-11-20T17:23:22.891Z","updated_at":"2025-03-14T18:43:24.402Z","avatar_url":"https://github.com/POABOB.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-discord\n\nThis is a discord backend project build with [go-zero](https://github.com/zeromicro/go-zero) and deploy on the Kubernetes.\n\n## Tech Stack\n\n- Remote Database Sevice: [Planetscale](https://app.planetscale.com)\n  - Database: [MySQL](https://www.mysql.com)\n  - Orm Library: [Prisma](https://www.prisma.io)\n- Framework: [go-zero](https://github.com/zeromicro/go-zero)\n- Kubernetes Service: [Scaleway](https://www.scaleway.com/en/)\n- User Management and Authentication Service: [Clerk](https://clerk.com)\n\n## Setup Prisma\n\n1. make sure you have remote DB on [planetscale](https://app.planetscale.com)\n\n2. get the `prisma-client-go` library\n\n```bash\n$ go get github.com/steebchen/prisma-client-go\n```\n\n3. define a prisma db schema, the code below is a demo schema\n\n`prisma/schema.prisma`\n```prisma\n// 使用別人寫好的 prisma-client-go 來連線\ngenerator client {\n  provider = \"go run github.com/steebchen/prisma-client-go\"\n}\n\n// DB 的類型、位置、模式\ndatasource db {\n  provider     = \"mysql\"\n  url          = env(\"DATABASE_URL\")\n  relationMode = \"prisma\"\n}\n\nmodel Post {\n  id        String   @default(cuid()) @id\n  createdAt DateTime @default(now())\n  updatedAt DateTime @updatedAt\n  title     String\n  published Boolean\n  desc      String?\n}\n```\n\n4. create .env file for DATABASE_URL\n\n`.env`\n```\nDATABASE_URL='mysql://user:password@host:3306/db_name?sslaccept=strict'\n```\n\n5. sync the database with the schema\n\n```bash\n$ go run github.com/steebchen/prisma-client-go db push\n# or regenerate the code\n$ go run github.com/steebchen/prisma-client-go generate\n```\n\n6. create demo.go for test\n\n`demo.go`\n```go\npackage main\n \nimport (\n  \"context\"\n  \"encoding/json\"\n  \"fmt\"\n\t\"os\"\n\n\t// the db orm was generated by github.com/steebchen/prisma-client-go\n\t\"github.com/POABOB/go-discord/prisma/db\"\n\t\"github.com/joho/godotenv\"\n)\n \nfunc main() {\n  if err := run(); err != nil {\n    panic(err)\n  }\n}\n \nfunc run() error {\n\tif err := godotenv.Load(); err != nil {\n\t\tfmt.Printf(\"Error loading .env file\\n\")\n\t}\n\tclient := db.NewClient(\n\t\tdb.WithDatasourceURL(os.Getenv(\"DATABASE_URL\")),\n\t)\n  if err := client.Prisma.Connect(); err != nil {\n    return err\n  }\n \n  defer func() {\n    if err := client.Prisma.Disconnect(); err != nil {\n      panic(err)\n    }\n  }()\n \n  ctx := context.Background()\n \n  // create a post\n  createdPost, err := client.Post.CreateOne(\n    db.Post.Title.Set(\"Hi from Prisma!\"),\n    db.Post.Published.Set(true),\n    db.Post.Desc.Set(\"Prisma is a database toolkit and makes databases easy.\"),\n  ).Exec(ctx)\n  if err != nil {\n    return err\n  }\n \n  result, _ := json.MarshalIndent(createdPost, \"\", \"  \")\n  fmt.Printf(\"created post: %s\\n\", result)\n \n  // find a single post\n  post, err := client.Post.FindUnique(\n    db.Post.ID.Equals(createdPost.ID),\n  ).Exec(ctx)\n  if err != nil {\n    return err\n  }\n \n  result, _ = json.MarshalIndent(post, \"\", \"  \")\n  fmt.Printf(\"post: %s\\n\", result)\n \n  // for optional/nullable values, you need to check the function and create two return values\n  // `desc` is a string, and `ok` is a bool whether the record is null or not. If it's null,\n  // `ok` is false, and `desc` will default to Go's default values; in this case an empty string (\"\"). Otherwise,\n  // `ok` is true and `desc` will be \"my description\".\n  desc, ok := post.Desc()\n  if !ok {\n    return fmt.Errorf(\"post's description is null\")\n  }\n \n  fmt.Printf(\"The posts's description is: %s\\n\", desc)\n \n  return nil\n}\n```\n\n7. run it\n\n```go\n$ go run demo.go\ncreated post: {\n  \"id\": \"ckfnrp7ec0000oh9kygil9s94\",\n  \"createdAt\": \"2020-09-29T09:37:44.628Z\",\n  \"updatedAt\": \"2020-09-29T09:37:44.628Z\",\n  \"title\": \"Hi from Prisma!\",\n  \"published\": true,\n  \"desc\": \"Prisma is a database toolkit and makes databases easy.\"\n}\npost: {\n  \"id\": \"ckfnrp7ec0000oh9kygil9s94\",\n  \"createdAt\": \"2020-09-29T09:37:44.628Z\",\n  \"updatedAt\": \"2020-09-29T09:37:44.628Z\",\n  \"title\": \"Hi from Prisma!\",\n  \"published\": true,\n  \"desc\": \"Prisma is a database toolkit and makes databases easy.\"\n}\nThe posts's title is: Prisma is a database toolkit and makes databases easy.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoabob%2Fgo-discord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoabob%2Fgo-discord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoabob%2Fgo-discord/lists"}