Beego
EC2에 서버를 올려서 테스트해볼 일이 잠깐 생겼다. 그래서 조금만 찍먹해본다.
Homepage - beego: simple & powerful Go app framework
MODULAR With powerful built-in modules including session control, caching, logging, configuration parsing, performance supervising, context handling, ORM supporting, and requests simulating. You get the powerful foundation for any type of applications.
beego.vip
그 전에 간략한 설명
1. beego가 뭔가?
- Go에서 Web Application, ORM, Logging 등 개발에 필요한 몇 가지 편의기능을 통합해서 제공하는 프레임워크라고 보면 될 것 같다.
2. 그래서 왜 beego를 썼는가?
- 간단하게 요청만 받는 서버를 구축하는게 목표라서 대강 쓸어보다 손에 잡히는걸로 골랐다! 다른 고려사항 없었음
선택의 이유는 멍청했지만 잠깐 쓸 것을 고르느라 오래 탐색하는게 오히려 시간낭비일 것이라고 생각했다. 아무튼 간단하게 시작
1. 설치
그냥 페이지 가장 앞단의 튜토리얼 따라갔다.
go get github.com/beego/beego/v2@v2.0.0
touch hello.go
echo "package main" >> hello.go
echo "import \"github.com/beego/beego/v2/server/web\"" >> hello.go
echo "func main() {" >> hello.go
echo " web.Run()" >> hello.go
echo "}" >> hello.go
go build hello.go
./hello
대충 빈 폴더에 붙여넣기하면 돌아갈 것이다.
이후 http://localhost:8080에 들어가면 화면이 잘 나온다.
이제 이걸 꾸며볼 것이다.
2. routing
이제 getting started 보고 따라간다.
Getting started - beego: simple & powerful Go app framework
Installation Beego contains sample applications to help you learn and use the Beego app framework. You will need a Go 1.1+ installation for this to work. You will need to install or upgrade Beego and the Bee dev tool: go get -u github.com/beego/beego/v2 go
beego.vip
beego의 버전이 바뀌면 명령어도 바뀔 수 있으므로 여기는 작성을 생략할 것임!
그래서 작성된 간단한 예시코드
package main
import (
"github.com/beego/beego/v2/server/web"
)
type MainController struct {
web.Controller
}
func (this *MainController) Get() {
this.Ctx.WriteString("hello world")
}
func main() {
web.Router("/test", &MainController{})
web.Run()
}
사실 복붙이다. 심플한 자료지만 꽤 다양한 정보가 들어있다.
1. web.Controller 이름으로 된 anonymous field는 web.Router의 라우팅 대상이 된다.
2. MainController의 Get()이 즉시 호출되는 것으로 보아, REST API 형식의 메소드명을 선언하면 자동으로 해당 내용을 호출할 것으로 보인다. 메소드 선택 방식은 아마 web.Router쪽에 추가적인 파라미터가 주어져서 사용되지 않을까?
가능성이 높아보인다.
-> 아닌 것 같다
'기술 > Go' 카테고리의 다른 글
[golint] exported method CrawlURLS returns unexported type []services.importerURL, which can be annoying to use (0) | 2022.04.12 |
---|
댓글