{"id":37467696,"url":"https://github.com/hosomi/go-gin-first-step","last_synced_at":"2026-01-16T07:11:50.622Z","repository":{"id":42672590,"uuid":"294572853","full_name":"hosomi/go-gin-first-step","owner":"hosomi","description":"Go lang \u0026 Gin Web Framework first step.","archived":false,"fork":false,"pushed_at":"2025-08-15T07:53:02.000Z","size":157,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-15T09:25:29.949Z","etag":null,"topics":["first-step","go","go-gin","mysql-docker","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hosomi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-09-11T02:25:03.000Z","updated_at":"2022-03-29T00:15:44.000Z","dependencies_parsed_at":"2024-02-21T06:26:09.825Z","dependency_job_id":"55bf13ee-d238-453c-bd06-4b9302aa27fd","html_url":"https://github.com/hosomi/go-gin-first-step","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hosomi/go-gin-first-step","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosomi%2Fgo-gin-first-step","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosomi%2Fgo-gin-first-step/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosomi%2Fgo-gin-first-step/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosomi%2Fgo-gin-first-step/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hosomi","download_url":"https://codeload.github.com/hosomi/go-gin-first-step/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosomi%2Fgo-gin-first-step/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["first-step","go","go-gin","mysql-docker","rest-api"],"created_at":"2026-01-16T07:11:50.544Z","updated_at":"2026-01-16T07:11:50.604Z","avatar_url":"https://github.com/hosomi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go lang \u0026 Gin Web Framework first step.\n\n:link: [The Go Programming Language](https://golang.org/)  \n:link: [Gin Web Framework](https://gin-gonic.com/)  \n\n## 1. basic start of the first step.\n\n## 1.1 basic setup\n\nenvironment:  \n\n- Windows10\n- PowerShell\n- Visual Studio Code :link: [Visual Studio Code – コード エディター | Microsoft Azure](https://azure.microsoft.com/ja-jp/products/visual-studio-code/)\n- Go lang -\u003e msi package(:link: [Download and install - The Go Programming Language](https://golang.org/doc/install?download=go1.15.2.windows-amd64.msi)) \n\n\n```powershell\nPS \u003e go version\ngo version go1.15.2 windows/amd64\n\nPS \u003e mkdir go-gin-first-step\nPS \u003e cd go-gin-first-step\n\nPS go-gin-first-step\u003e go mod init gin_test\ngo: creating new go.mod: module gin_test\n\nPS go-gin-first-step\u003e go get -u github.com/gin-gonic/gin\ngo: downloading github.com/gin-gonic/gin v1.6.3\ngo: github.com/gin-gonic/gin upgrade =\u003e v1.6.3\ngo: downloading github.com/gin-contrib/sse v0.1.0\ngo: downloading github.com/golang/protobuf v1.3.3\ngo: downloading gopkg.in/yaml.v2 v2.2.8\ngo: downloading github.com/json-iterator/go v1.1.9\ngo: downloading github.com/mattn/go-isatty v0.0.12\ngo: downloading github.com/go-playground/validator/v10 v10.2.0\ngo: downloading github.com/ugorji/go v1.1.7\ngo: downloading golang.org/x/sys v0.0.0-20200116001909-b77594299b42\ngo: downloading github.com/ugorji/go/codec v1.1.7\ngo: downloading github.com/leodido/go-urn v1.2.0\ngo: downloading github.com/go-playground/universal-translator v0.17.0\ngo: downloading github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742\ngo: downloading github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421\ngo: downloading github.com/go-playground/locales v0.13.0\ngo: github.com/modern-go/reflect2 upgrade =\u003e v1.0.1\ngo: github.com/golang/protobuf upgrade =\u003e v1.4.2\ngo: github.com/modern-go/concurrent upgrade =\u003e v0.0.0-20180306012644-bacd9c7ef1dd\ngo: gopkg.in/yaml.v2 upgrade =\u003e v2.3.0\ngo: github.com/go-playground/validator/v10 upgrade =\u003e v10.3.0\ngo: github.com/json-iterator/go upgrade =\u003e v1.1.10\ngo: golang.org/x/sys upgrade =\u003e v0.0.0-20200909081042-eff7692f9009\ngo: downloading gopkg.in/yaml.v2 v2.3.0\ngo: downloading github.com/json-iterator/go v1.1.10\ngo: downloading github.com/golang/protobuf v1.4.2\ngo: downloading github.com/go-playground/validator/v10 v10.3.0\ngo: downloading golang.org/x/sys v0.0.0-20200909081042-eff7692f9009\ngo: downloading google.golang.org/protobuf v1.23.0\ngo: downloading github.com/modern-go/reflect2 v1.0.1\ngo: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd\ngo: google.golang.org/protobuf upgrade =\u003e v1.25.0\ngo: downloading google.golang.org/protobuf v1.25.0\n\nPS go-gin-first-step\u003e code .\n```\n\n## 1.2 go run\n\n```powershell\nPS go-gin-first-step\u003e go run main.go\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n[GIN-debug] [WARNING] Running in \"debug\" mode. Switch to \"release\" mode in production.\n - using env:   export GIN_MODE=release\n - using code:  gin.SetMode(gin.ReleaseMode)\n\n[GIN-debug] GET    /                         --\u003e main.main.func2 (4 handlers)\n[GIN-debug] Loaded HTML Templates (3):\n        - fileupload.html\n        - index.html\n        -\n\n[GIN-debug] GET    /templates                --\u003e main.main.func3 (4 handlers)\n[GIN-debug] GET    /static/*filepath         --\u003e github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (4 handlers)\n[GIN-debug] HEAD   /static/*filepath         --\u003e github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (4 handlers)\n[GIN-debug] GET    /upload                   --\u003e main.main.func4 (4 handlers)\n[GIN-debug] POST   /upload                   --\u003e main.main.func5 (4 handlers)\n[GIN-debug] Listening and serving HTTP on :3000\n```\n\n\n``http:localhost:3000`` :  \n\n| path       | method | description\n| ---------- | ------ | ---------------\n| /          | GET    | hello world json\n| /templates | GET    | template hello world\n| /static/*  | GET    | engine.Static (``http://localhost:3000/static/gin.png``)  *gin.png \n| /upload    | GET    | file upload front\n| /upload    | POST   | file upload /images \n\n*gin.png ：:link: [gin-gonic/gin: Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.](https://github.com/gin-gonic/gin)   \n\n---\n\n[history](https://github.com/hosomi/go-gin-first-step/commits/master) :  \n1. [setup](https://github.com/hosomi/go-gin-first-step/commit/8714097b1800dc2ca73734414dd8c4f969281d69)  \n2. [hello world!](https://github.com/hosomi/go-gin-first-step/commit/5a2f66c5e9110f25ecc8f5070978bc10bdc784d0) ([branch : hello-world](https://github.com/hosomi/go-gin-first-step/tree/hello-world))\n3. [templates](https://github.com/hosomi/go-gin-first-step/commit/842f245406260292afc302f6bdc98e6d90e25798) ([branch : templates](https://github.com/hosomi/go-gin-first-step/tree/templates))\n4. [engine static](https://github.com/hosomi/go-gin-first-step/commit/aee3207b389d775f4305cdf0593ec71b63af2a4e) ([branch : static](https://github.com/hosomi/go-gin-first-step/tree/static))\n5. [fileupload \u0026 here document](https://github.com/hosomi/go-gin-first-step/commit/71289644bafd9970b8a68e7fc57238c1ea868990) ([branch : file-upload](https://github.com/hosomi/go-gin-first-step/tree/file-upload))\n\n　  \n\nbasic end. \n\n　  \n　  \n\n---\n\n## 2. first step next REST API configuration.\n\n### 2.1 setup database\n\nenvironment:  \n- MySQL 8.x(docker)\n\n```powershell\ngo-gin-first-step\n│  docker-compose.yml\n│\n└─docker\n   └─mysql\n       │  Dockerfile\n       │\n       ├─conf.d\n       │      my.cnf\n       │\n       ├─data\n       │\n       └─initdb.d\n              create_db.sql\n```\n\n1. docker-compose up -d\n2. docker-compose ps\n3. mysql -uroot -prootpassword -h 127.0.0.1 -P 3306\n\n---\n\nlogs: \n\n1. ``docker-compose up -d``:  \n\n```powershell\nPS go-gin-first-step\u003e docker-compose up -d\nCreating network \"go-gin-first-step_default\" with the default driver\nStep 1/2 : FROM mysql:8\n8: Pulling from library/mysql\nd121f8d1c412: Pull complete\nf3cebc0b4691: Pull complete\n1862755a0b37: Pull complete\n489b44f3dbb4: Pull complete\n690874f836db: Pull complete\nbaa8be383ffb: Pull complete\n55356608b4ac: Pull complete\ndd35ceccb6eb: Pull complete\n429b35712b19: Pull complete\n162d8291095c: Pull complete\n5e500ef7181b: Pull complete\naf7528e958b6: Pull complete\nDigest: sha256:e1bfe11693ed2052cb3b4e5fa356c65381129e87e38551c6cd6ec532ebe0e808\nStatus: Downloaded newer image for mysql:8\n ---\u003e e1d7dc9731da\nStep 2/2 : EXPOSE 3306\n ---\u003e Running in 62e45392cc93\nRemoving intermediate container 62e45392cc93\n ---\u003e 2bd982e2e863\n\nSuccessfully built 2bd982e2e863\nSuccessfully tagged go-gin-first-step_mysql:latest\nWARNING: Image for service mysql was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.\nCreating mysql ... done\n```\n\n\n2. ``docker-compose ps``:  \n\n```powershell\nName              Command             State                 Ports\n-------------------------------------------------------------------------------\nmysql   docker-entrypoint.sh mysqld   Up      0.0.0.0:3306-\u003e3306/tcp, 3306/tcp\n```\n\n3. ``mysql -uroot -prootpassword -h 127.0.0.1 -P 3306``:  \n\n```powershell\nPS go-gin-first-step\u003e mysql -uroot -prootpassword -h 127.0.0.1 -P 3306\nmysql: [Warning] Using a password on the command line interface can be insecure.\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 9\nServer version: 8.0.21 MySQL Community Server - GPL\n\nCopyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql\u003e show databases;\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| mysql              |\n| performance_schema |\n| sys                |\n| test               |\n+--------------------+\n5 rows in set (0.01 sec)\n\nmysql\u003e exit\nBye\n\nPS go-gin-first-step\u003e\n```\n\n\n### 2.2 packages setup\n\n* [mysql package · pkg.go.dev](https://pkg.go.dev/github.com/go-sql-driver/mysql?tab=doc)  \n``go get github.com/go-sql-driver/mysql``  \n\n* [xorm package · pkg.go.dev](https://pkg.go.dev/github.com/go-xorm/xorm?tab=doc)  \n``go get github.com/go-xorm/xorm``  \n\n* [zap package · pkg.go.dev](https://pkg.go.dev/go.uber.org/zap?tab=doc)  \n``go get go.uber.org/zap``  \n\n\nlogs:  \n\n```powershell\nPS go-gin-first-step\u003e go get github.com/go-sql-driver/mysql\ngo: downloading github.com/go-sql-driver/mysql v1.5.0\ngo: github.com/go-sql-driver/mysql upgrade =\u003e v1.5.0\nPS go-gin-first-step\u003e go get github.com/go-xorm/xorm\ngo: downloading github.com/go-xorm/xorm v0.7.9\ngo: github.com/go-xorm/xorm upgrade =\u003e v0.7.9\ngo: downloading xorm.io/builder v0.3.6\ngo: downloading xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb\nPS go-gin-first-step\u003e go get go.uber.org/zap\ngo: downloading go.uber.org/zap v1.16.0\ngo: go.uber.org/zap upgrade =\u003e v1.16.0\ngo: downloading go.uber.org/atomic v1.6.0\ngo: downloading go.uber.org/multierr v1.5.0\n```\n\n### 2.3 folder structur\n\n```powershell\ngo-gin-first-step\n│  main.go\n│\n├─controller\n│      book.go\n│\n├─middleware\n│      bookMiddleware.go\n│\n├─model\n│      book.go\n│\n└─service\n       book.go\n       init.go\n```\n\n### 2.4 go run\n\n``go run main.go`` :  \n\nlogs:  \n\n```powershell\nPS go-gin-first-step\u003e go run main.go\n[xorm] [info]  2020/09/14 11:39:44.722407 [SQL] SELECT `TABLE_NAME`, `ENGINE`, `TABLE_ROWS`, `AUTO_INCREMENT`, `TABLE_COMMENT` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB' OR `ENGINE` = 'TokuDB') [test]\n[xorm] [info]  2020/09/14 11:39:45.648517 [SQL] CREATE TABLE IF NOT EXISTS `book` (`id` INT(64) PRIMARY KEY AUTO_INCREMENT NOT NULL, `title` VARCHAR(40) NULL, `content` VARCHAR(40) NULL) DEFAULT CHARSET utf8\ninit data base ok\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n[GIN-debug] [WARNING] Running in \"debug\" mode. Switch to \"release\" mode in production.\n - using env:   export GIN_MODE=release\n - using code:  gin.SetMode(gin.ReleaseMode)\n\n[GIN-debug] GET    /                         --\u003e main.main.func2 (4 handlers)\n[GIN-debug] Loaded HTML Templates (3):\n        -\n        - fileupload.html\n        - index.html\n\n[GIN-debug] GET    /templates                --\u003e main.main.func3 (4 handlers)\n[GIN-debug] GET    /static/*filepath         --\u003e github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (4 handlers)\n[GIN-debug] HEAD   /static/*filepath         --\u003e github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (4 handlers)\n[GIN-debug] GET    /upload                   --\u003e main.main.func4 (4 handlers)\n[GIN-debug] POST   /upload                   --\u003e main.main.func5 (4 handlers)\n[GIN-debug] POST   /book/v1/add              --\u003e gin_test/controller.BookAdd (5 handlers)\n[GIN-debug] GET    /book/v1/list             --\u003e gin_test/controller.BookList (5 handlers)\n[GIN-debug] PUT    /book/v1/update           --\u003e gin_test/controller.BookUpdate (5 handlers)\n[GIN-debug] DELETE /book/v1/delete           --\u003e gin_test/controller.BookDelete (5 handlers)\n[GIN-debug] Listening and serving HTTP on :3000\n```\n\ncheck ``/book/v1/`` endpoints.\n\nnext,  \ncheck that a book table is created in the MySQL test database.  \n\nPowerShell:  \n\n```powershell\nPS\u003e mysql -uroot -prootpassword -h 127.0.0.1 -P 3306\n```\n\nMySQL:  \n\n```sql\nmysql\u003e use test;\nmysql\u003e show tables;\nmysql\u003e describe book;\nmysql\u003e exit;\n```\n\nlogs:  \n\n```powershell\nPS \u003e mysql -uroot -prootpassword -h 127.0.0.1 -P 3306\nmysql: [Warning] Using a password on the command line interface can be insecure.\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 13\nServer version: 8.0.21 MySQL Community Server - GPL\n\nCopyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql\u003e use test;\nDatabase changed\nmysql\u003e show tables;\n+----------------+\n| Tables_in_test |\n+----------------+\n| book           |\n+----------------+\n1 row in set (0.00 sec)\n\nmysql\u003e describe book;\n+---------+-------------+------+-----+---------+----------------+\n| Field   | Type        | Null | Key | Default | Extra          |\n+---------+-------------+------+-----+---------+----------------+\n| id      | int         | NO   | PRI | NULL    | auto_increment |\n| title   | varchar(40) | YES  |     | NULL    |                |\n| content | varchar(40) | YES  |     | NULL    |                |\n+---------+-------------+------+-----+---------+----------------+\n3 rows in set (0.01 sec)\n\nmysql\u003e exit\nBye\n```\n\n### 2.5 book API tests\n\n| path            | method | description\n| --------------- | ------ | ---------------\n| /book/v1/add    | POST   | adding new data to the book\n| /book/v1/list   | GET    | retrieve a list of book data\n| /book/v1/update | PUT    | updating the book's data\n| /book/v1/delete | DELETE | deletion of book data\n\n---\n\nthe test is done with cURL(for Windows).  \n(it is also recommended to refer to the data in your MySQL client.)   \n:link: [curl for Windows](https://curl.haxx.se/windows/)  \n\n* ``POST: /book/v1/add`` : \n\n```powershell\nPS \u003e ./curl --location --request POST \"http://localhost:3000/book/v1/add\" --form \"title=title\" --form \"content=content\"\n{\"status\":\"ok\"}\n```\n\n\n* ``GET: /book/v1/list`` : \n\n```powershell\nPS \u003e ./curl --location --request GET \"http://localhost:3000/book/v1/list\"\n{\"data\":[{\"id\":1,\"title\":\"title\",\"content\":\"content\"}],\"message\":\"ok\"}\n```\n\n\n* ``PUT: /book/v1/update`` :\n\n```powershell\nPS \u003e ./curl --location --request PUT \"http://localhost:3000/book/v1/update\" --form \"id=1\" --form \"title=title-update\" --form \"content=content-update\"\n{\"status\":\"ok\"}\n```\n\n\n* ``DELETE: /book/v1/delete`` :\n\n```powershell\nPS \u003e ./curl --location --request DELETE \"http://localhost:3000/book/v1/delete\" --form  \"id=1\"\n{\"status\":\"ok\"}\n```\n\n\n---\n\nMySQL client reference examples:  \n\n```powershell\nPS \u003e mysql -uroot -prootpassword -h 127.0.0.1 -P 3306\nmysql: [Warning] Using a password on the command line interface can be insecure.\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 8\nServer version: 8.0.21 MySQL Community Server - GPL\n\nCopyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql\u003e use test;\nDatabase changed\nmysql\u003e select * from book;\n+----+-------+---------+\n| id | title | content |\n+----+-------+---------+\n|  1 | title | content |\n+----+-------+---------+\n1 row in set (0.00 sec)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhosomi%2Fgo-gin-first-step","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhosomi%2Fgo-gin-first-step","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhosomi%2Fgo-gin-first-step/lists"}