Golang 및 api 사이트 참고
Golang
https://velog.io/@csh6222/Golang-%ED%95%A8%EC%88%98%EC%A0%95%EB%A6%AC
Golang 함수정리
특정 기능을 위해 만든 여러 문장을 묶어서 실행하는 코드 블록 단위.프로그램의 특정 기능들을 기능별로 묶어 구현해놓은 것.func 함수명 (매개변수들) (반환형들){
velog.io
예제로 배우는 Go 프로그래밍 - 간단한 웹 서버 (HTTP 서버)
1. 간단한 HTTP 서버 Go의 표준 패키지인 net/http 패키지는 웹 관련 서버 (및 클라이언트) 기능을 제공한다. Go에서 HTTP 서버를 만들기 위해 중요한 http 패키지 메서드로 ListenAndServe(), Handle(), HandleFunc()
golang.site
Gin middleware 파악하기
Gin을 사용하여 웹앱과 마이크로서비스 만들기
개요 이 글은 Building Go Web Application and Microservices Using Gin이라는 제목의 글을 번역한 글로 어색한 번역과 오역이 존재할 수 있습니다. 원문: https://semaphoreci.com/community/tutorials/building..
earntrust.tistory.com
https://jusths.tistory.com/236?category=814645
Golang Gin Gonic - 1. Basic REST API
간단한 API 서버를 제외하고는 웹서비스의 전형적인 HTTP API server를 실무에서 개발한 적이 없다. 유튜브에서 Golang의 대표적인 web framework인 Gin을 이용한 좋은 강좌를 만나 이를 하나씩 따라하려고
jusths.tistory.com
https://bourbonkk.tistory.com/63
#4 Golang 인증 middleware 구현하기(gin framework)
오늘은 Golang을 이용한 API 서버를 구현하던 중! 소스코드를 아주 효율적으로 줄여줄 수 있는 ! 미들웨어를 작성해볼건데요! 이 미들웨어란 무엇을 이야기하는 걸까요? 미들웨어는 양 쪽을 연결하
bourbonkk.tistory.com
mongodb.go에서 Get의 FindeOne 부분을 이용해서 본인계정정보 확인 단계 진행
func (r *MongoDB) Get(opts ...*options.FindOneOptions) (interface{}, base.StatefulError) {
res := r.col.FindOne(r.ctx, r.doc, opts...)
if err := res.Err(); err != nil {
blog.Error(r.ctx, err.Error())
return nil, errors.ErrDatabaseQuery
}
res.Decode(r.doc)
return r.doc, nil
}
code-backend
controllers / v1.go 부분 line 17 ~ line 57
Authorization이 무엇인지 파악
func (r *V1API) Route(rg *base.RouteGroup) {
rg.Use(r.Authorization)
rg.Group("/session", &v1.SessionAPI{})
rg.Group("/code", &v1.CodeAPI{})
rg.Group("/algorithm", &v1.AlgorithmAPI{})
rg.Group("/class", &v1.ClassAPI{})
user := &v1.UserAPI{}
rg.GET("/user/", user.GetUser)
rg.GET("/user/search", user.SearchUser)
}
type AuthorizationReq struct {
base.HeaderRequester `json:"-"`
Authorization string `header:"authorization"`
}
type AuthorizationResp struct {
}
func (r *V1API) Authorization(ctx *base.Context, req AuthorizationReq) (err base.StatefulError) {
blog.Debug(ctx, "authorization api")
defer func() {
if e := recover(); e != nil {
blog.Error(ctx, e)
err = errors.ErrIncorrectToken
}
}()
var user interface{}
if u, p, ok := ctx.Request.BasicAuth(); ok {
user, err = r.validateBasic(ctx, u, p)
} else {
user, err = r.validateToken(ctx, req.Authorization)
}
ctx.SetField(base.ContextUser, user)
return err
}
아래 validateToken 및 validateBasic 코드 분석
func (r *V1API) validateToken(ctx *base.Context, auth string) (interface{}, base.StatefulError) {
err := (base.StatefulError)(nil)
tk := security.New(ctx, "", map[string]interface{}{})
t := token.Token{
Token: auth,
}
db := mongodb.New(ctx, &t)
if _, err = db.Get(); err != nil {
blog.Error(ctx, err.Error())
return "", errors.ErrIncorrectToken
}
_, claims, err := tk.Validate(auth)
return claims[security.ClaimUser], err
}
func (r *V1API) validateBasic(ctx *base.Context, email, password string) (interface{}, base.StatefulError) {
u := user.User{
Email: email,
Password: password,
}
db := mongodb.New(ctx, &u)
_, err := db.Get()
if err != nil {
blog.Error(ctx, err.Error())
return nil, errors.ErrWrongPassword
}
return email, nil
}
kaikas 지갑 계설 주소 확인
Klaytnscope
Klaytnscope
Klaytnscope allows you to find data by monitoring network health and statistics of Klaytn as well as profiling blocks and transactions on Klaytn.
scope.klaytn.com
OpenSea
발표 내용 정리
- golang 입문 (tour of go) / gin framework middleware
- docker(12 / 23)일부터
- jwt
- pa-backend / code-backend,
- airdrop-file-generator
'MadApp' 카테고리의 다른 글
OJT 2022-03-04 (0) | 2022.03.13 |
---|---|
OJT 2022-02-21 (0) | 2022.03.13 |
(GolangPractice Day1) OJT 2021-12-09 KJH (0) | 2022.03.13 |
Share(PAN-59 UI 로그인 로고 변경) OJT 2021-12-08 권재현 (0) | 2022.03.13 |
OJT 2021-12-07 KJH SSH (Secure Shell) (0) | 2022.03.13 |