{"id":23722818,"url":"https://github.com/nmdra/snipbox","last_synced_at":"2026-05-01T21:03:41.673Z","repository":{"id":267082498,"uuid":"891844678","full_name":"nmdra/snipbox","owner":"nmdra","description":"Repo for snippetbox project as part of Let's Go! book by Alex Edwards.","archived":false,"fork":false,"pushed_at":"2025-06-25T14:40:23.000Z","size":72,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-30T13:37:44.511Z","etag":null,"topics":["docker","docker-compose","go","go-api","go-app","letsgo"],"latest_commit_sha":null,"homepage":"https://blog.nimendra.xyz","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nmdra.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,"zenodo":null}},"created_at":"2024-11-21T03:49:57.000Z","updated_at":"2025-07-24T18:41:14.000Z","dependencies_parsed_at":"2025-06-25T15:37:03.457Z","dependency_job_id":null,"html_url":"https://github.com/nmdra/snipbox","commit_stats":null,"previous_names":["nmdra/snipbox"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nmdra/snipbox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdra%2Fsnipbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdra%2Fsnipbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdra%2Fsnipbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdra%2Fsnipbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nmdra","download_url":"https://codeload.github.com/nmdra/snipbox/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmdra%2Fsnipbox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32512670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["docker","docker-compose","go","go-api","go-app","letsgo"],"created_at":"2024-12-30T23:57:12.190Z","updated_at":"2026-05-01T21:03:41.645Z","avatar_url":"https://github.com/nmdra.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snipbox\n\n\u003ca href=\"https://golang.org/doc/go1.23\"\u003e\u003cimg alt=\"Go 1.23\" src=\"https://img.shields.io/badge/golang-1.23-blue?logo=go\u0026color=5EC9E3\"\u003e\u003c/a\u003e\n\nRepo for snippetbox project as part of Let's Go! book by Alex Edwards \n(found [here](https://lets-go.alexedwards.net))\n\n## ✨ My Changes\nThis section highlights the modifications made to the original project as described in the Let's Go book:\n\n- Creating a Docker-driven Go development workflow\n- Add live realod using [air-verse/air](https://github.com/air-verse/air)\n- Add Docker image (production)\n\n---\n## Setup Mysql docker container \n\n### Docker Compose File\n\n```yml\nservices:\n  web:\n    build:\n      context: .\n      dockerfile: Dockerfile\n    container_name: snipbox-dev\n    ports:\n      - \"4000:4000\" # default app port\n      - \"4001:4001\" # air proxy port (Optional)\n    environment:\n      - PORT=4000 # default app port \n    volumes:\n      - ./:/app\n    networks:\n      - snipbox-net\n    depends_on:\n      db:\n        condition: service_healthy\n\n  db:\n    image: mysql:lts \n    container_name: snipbox-db\n    restart: unless-stopped\n    environment:\n      MYSQL_ROOT_PASSWORD: root\n      MYSQL_DATABASE: snippetbox\n      MYSQL_USER: web\n      MYSQL_PASSWORD: pass\n    ports:\n      - \"3306:3306\" # Optinal\n    volumes:\n      - mysql-data:/var/lib/mysql\n    networks:\n      - snipbox-net\n    healthcheck:\n      test: [\"CMD\", \"mysqladmin\", \"ping\", \"-h\", \"localhost\"]\n      interval: 5s\n      timeout: 5s\n      retries: 2\n  \nvolumes:\n  mysql-data:\n    external: true # Use external vluume for data persistence\n\nnetworks:\n  snipbox-net:\n    driver: bridge\n```\n\n### Setup User\n\n\u003e  [!IMPORTANT]  \n\u003e  **We use `%` instead of `localhost` because**:\n\u003e - `'localhost'` restricts the user to connect **only from the same machine** where the MySQL server is running.\n\u003e - In this workflow, MySQL runs in a separate container, so `localhost` doesn't work for external connections.\n\u003e - Using `%` allows the user to connect from any host, enabling communication between containers.\n\n\n1. Create User\n```sql\nCREATE USER 'web'@'%';\n```\n\n2. Grant access\n```sql\nGRANT SELECT, INSERT, UPDATE, DELETE ON snippetbox.* TO 'web'@'%';\n```\n\n```sql\n-- Important: Make sure to swap 'pass' with a password of your own choosing.\nALTER USER 'web'@'%' IDENTIFIED BY 'pass';\n```\n\n3. Check users\n```sql\nSELECT user, host FROM mysql.user;\n```\n\n4. Connection String\n```go\ndsn := flag.String(\"dsn\", \"web:pass@tcp(mysql:3306)/snippetbox?parseTime=true\", \"MySQL data source name\")\n```\n\n## Docker Compose Production\n\n\u003e [!TIP]\n\u003e Create self signed tls certificate \u0026 create `.env` before run docker compose\n\u003e the generate_cert.go file should be located under  `/usr/local/go/src/crypto/tls` or `/usr/lib/go/src/crypto/tls` (Manjaro/Arch)\n\u003e \n\u003e #### Generate Certificate\n\u003e ```bash\n\u003e mkdir -p tls\n\u003e cd tls\n\u003e go run /usr/local/go/src/crypto/tls/generate_cert.go --rsa-bits=2048 --host=localhost\n\u003e ``` \n\n```yml\nservices:\n  web:\n    image: ghcr.io/nmdra/snipbox:latest\n    container_name: snipbox-prod\n    ports:\n      - \"4000:4000\" # default app port\n    env_file:\n      - .env\n    volumes:\n      - ./tls/:/tls/ # TLS cert directory\n    networks:\n      - snipbox-net\n    depends_on:\n      db:\n        condition: service_healthy\n\n  db:\n    image: mysql:lts \n    # container_name: snipbox-db\n    restart: unless-stopped\n    environment:\n      MYSQL_ROOT_PASSWORD: root\n      MYSQL_DATABASE: snippetbox\n      MYSQL_USER: web\n      MYSQL_PASSWORD: pass\n    ports:\n      - \"3306:3306\" # Expose MySQL port (Optional)\n    volumes:\n      - mysql-data:/var/lib/mysql\n    networks:\n      - snipbox-net\n    healthcheck:\n      test: [\"CMD\", \"mysqladmin\", \"ping\", \"-h\", \"localhost\"]\n      interval: 5s\n      timeout: 5s\n      retries: 2\n  \nvolumes:\n  mysql-data:\n    external: true\n\nnetworks:\n  snipbox-net:\n    driver: bridge\n```\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"blog.nimendra.xyz\"\u003e 🌎 nmdra.xyz\u003c/a\u003e |\n  \u003ca href=\"https://github.com/nmdra\"\u003e 👨‍💻 Github\u003c/a\u003e |\n  \u003ca href=\"https://twitter.com/nimendra_\"\u003e 🐦 Twitter\u003c/a\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmdra%2Fsnipbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnmdra%2Fsnipbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmdra%2Fsnipbox/lists"}