From 9df3759e5ead18a8c9bc4c63bf027f1e61086a76 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 30 Jan 2025 15:54:49 +0900 Subject: [PATCH 1/7] Initialize echo backend project --- backend-go/.gitignore | 28 ++++++++++++++++++++++++++++ backend-go/Makefile | 16 ++++++++++++++++ backend-go/cmd/codepair/main.go | 15 +++++++++++++++ backend-go/go.mod | 16 ++++++++++++++++ backend-go/go.sum | 23 +++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 backend-go/.gitignore create mode 100644 backend-go/Makefile create mode 100644 backend-go/cmd/codepair/main.go create mode 100644 backend-go/go.mod create mode 100644 backend-go/go.sum diff --git a/backend-go/.gitignore b/backend-go/.gitignore new file mode 100644 index 00000000..250a46dd --- /dev/null +++ b/backend-go/.gitignore @@ -0,0 +1,28 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env + +# bin +bin \ No newline at end of file diff --git a/backend-go/Makefile b/backend-go/Makefile new file mode 100644 index 00000000..936eca6f --- /dev/null +++ b/backend-go/Makefile @@ -0,0 +1,16 @@ +CODEPAIR_VERSION := 0.2.0 + +default: help + +tools: ## install tools for developing codepair + @echo "TODO: add tools" + +build: ## builds an executable that runs in the current environment + go build -o ./bin/codepair cmd/codepair/main.go + +help: + @echo 'Commands:' + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}' + @echo + +.PHONY: tools help diff --git a/backend-go/cmd/codepair/main.go b/backend-go/cmd/codepair/main.go new file mode 100644 index 00000000..708d7048 --- /dev/null +++ b/backend-go/cmd/codepair/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "net/http" + + "github.com/labstack/echo/v4" +) + +func main() { + e := echo.New() + e.GET("/", func(c echo.Context) error { + return c.String(http.StatusOK, "Hello, World!") + }) + e.Logger.Fatal(e.Start(":3001")) +} diff --git a/backend-go/go.mod b/backend-go/go.mod new file mode 100644 index 00000000..5d694f6f --- /dev/null +++ b/backend-go/go.mod @@ -0,0 +1,16 @@ +module codepair/backend + +go 1.23.3 + +require ( + github.com/labstack/echo/v4 v4.13.3 // indirect + github.com/labstack/gommon v0.4.2 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasttemplate v1.2.2 // indirect + golang.org/x/crypto v0.31.0 // indirect + golang.org/x/net v0.33.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect +) diff --git a/backend-go/go.sum b/backend-go/go.sum new file mode 100644 index 00000000..58bdfb66 --- /dev/null +++ b/backend-go/go.sum @@ -0,0 +1,23 @@ +github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY= +github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g= +github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= +github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= +github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= From 15d3a4f67467bc9af9eb9d5c72aeefbd256e8576 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 30 Jan 2025 16:19:42 +0900 Subject: [PATCH 2/7] Add `fmt` and `lint` command --- backend-go/.golangci.yml | 23 +++++++++++++++++++++++ backend-go/Makefile | 10 ++++++++-- backend-go/README.md | 27 +++++++++++++++++++++++++++ backend-go/cmd/codepair/main.go | 4 +++- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 backend-go/.golangci.yml create mode 100644 backend-go/README.md diff --git a/backend-go/.golangci.yml b/backend-go/.golangci.yml new file mode 100644 index 00000000..bf333e7a --- /dev/null +++ b/backend-go/.golangci.yml @@ -0,0 +1,23 @@ +run: + deadline: 5m + +linters: + enable: + - errcheck + - goimports + - govet + - goconst + - gocyclo + - gofmt + - revive + - goprintffuncname + - gosec + - lll + - misspell + - nakedret + - wrapcheck + disable: + - gosimple + - staticcheck + - structcheck + - unused \ No newline at end of file diff --git a/backend-go/Makefile b/backend-go/Makefile index 936eca6f..315394c9 100644 --- a/backend-go/Makefile +++ b/backend-go/Makefile @@ -3,14 +3,20 @@ CODEPAIR_VERSION := 0.2.0 default: help tools: ## install tools for developing codepair - @echo "TODO: add tools" + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1 build: ## builds an executable that runs in the current environment go build -o ./bin/codepair cmd/codepair/main.go +fmt: ## applies format and simplify codes + go fmt ./... + +lint: ## runs the golang-ci lint, checks for lint violations + golangci-lint run + help: @echo 'Commands:' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}' @echo -.PHONY: tools help +.PHONY: tools build fmt lint help diff --git a/backend-go/README.md b/backend-go/README.md new file mode 100644 index 00000000..79c28e1a --- /dev/null +++ b/backend-go/README.md @@ -0,0 +1,27 @@ +# CodePair Service Backend + +This project is the backend part of the CodePair service developed using Go. +It is being migrated from the NestJS framework to Go. (Related Issue: [#430](https://github.com/yorkie-team/codepair/issues/430)) + +## Setting Developing Environment + +### Requirements + +Below are needed for developing and building Yorkie. + +- [Go](https://golang.org) (version 1.18+) + +### Building & Testing + +You can build the CodePair project by running the following command. + +```sh +make tools +make build # executable: ./bin/codepair +``` + +You can automatically check the programmatic and stylistic errors of your code. + +```sh +make lint +``` diff --git a/backend-go/cmd/codepair/main.go b/backend-go/cmd/codepair/main.go index 708d7048..cd7a16fc 100644 --- a/backend-go/cmd/codepair/main.go +++ b/backend-go/cmd/codepair/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "net/http" "github.com/labstack/echo/v4" @@ -9,7 +10,8 @@ import ( func main() { e := echo.New() e.GET("/", func(c echo.Context) error { - return c.String(http.StatusOK, "Hello, World!") + err := c.String(http.StatusOK, "Hello, World!") + return fmt.Errorf("error: %w", err) }) e.Logger.Fatal(e.Start(":3001")) } From d2d2f8a2405fe0a502c9cd8c07c996c88739019b Mon Sep 17 00:00:00 2001 From: LeeJongBeom <52884648+devleejb@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:26:13 +0900 Subject: [PATCH 3/7] Update backend-go/README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- backend-go/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend-go/README.md b/backend-go/README.md index 79c28e1a..f811c9f0 100644 --- a/backend-go/README.md +++ b/backend-go/README.md @@ -7,7 +7,7 @@ It is being migrated from the NestJS framework to Go. (Related Issue: [#430](htt ### Requirements -Below are needed for developing and building Yorkie. +Below are needed for developing and building CodePair. - [Go](https://golang.org) (version 1.18+) From 989d1d26ba68267e9a5212d122ad32af1d16f618 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 30 Jan 2025 16:27:45 +0900 Subject: [PATCH 4/7] Add `test` and `clean` command --- backend-go/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend-go/Makefile b/backend-go/Makefile index 315394c9..e1d0a205 100644 --- a/backend-go/Makefile +++ b/backend-go/Makefile @@ -14,9 +14,15 @@ fmt: ## applies format and simplify codes lint: ## runs the golang-ci lint, checks for lint violations golangci-lint run +test: ## run tests + go test -v ./... + +clean: ## remove build artifacts + rm -rf ./bin + help: @echo 'Commands:' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}' @echo -.PHONY: tools build fmt lint help +.PHONY: tools build fmt lint test clean help From 8aeab9326877c75ae5dd5b5c2ea7e9810922d942 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 30 Jan 2025 17:17:42 +0900 Subject: [PATCH 5/7] Change build command to package level --- backend-go/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend-go/Makefile b/backend-go/Makefile index e1d0a205..f57b1ae5 100644 --- a/backend-go/Makefile +++ b/backend-go/Makefile @@ -6,7 +6,7 @@ tools: ## install tools for developing codepair go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1 build: ## builds an executable that runs in the current environment - go build -o ./bin/codepair cmd/codepair/main.go + go build -o ./bin/codepair ./cmd/codepair fmt: ## applies format and simplify codes go fmt ./... From 5222f0475091fa690c95db24fea69dd2514a0d97 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 30 Jan 2025 17:19:22 +0900 Subject: [PATCH 6/7] Add POSIX newline --- backend-go/.gitignore | 2 +- backend-go/.golangci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend-go/.gitignore b/backend-go/.gitignore index 250a46dd..9af05ea6 100644 --- a/backend-go/.gitignore +++ b/backend-go/.gitignore @@ -25,4 +25,4 @@ go.work.sum .env # bin -bin \ No newline at end of file +bin diff --git a/backend-go/.golangci.yml b/backend-go/.golangci.yml index bf333e7a..16e9a201 100644 --- a/backend-go/.golangci.yml +++ b/backend-go/.golangci.yml @@ -20,4 +20,4 @@ linters: - gosimple - staticcheck - structcheck - - unused \ No newline at end of file + - unused From 6cde04c9e44c12bb4c1d5c8020238b8229116cac Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 30 Jan 2025 18:50:31 +0900 Subject: [PATCH 7/7] Change module name --- backend-go/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend-go/go.mod b/backend-go/go.mod index 5d694f6f..17183559 100644 --- a/backend-go/go.mod +++ b/backend-go/go.mod @@ -1,4 +1,4 @@ -module codepair/backend +module github.com/yorkie-team/codepair/backend go 1.23.3