Skip to content

Commit

Permalink
[1126] section 85
Browse files Browse the repository at this point in the history
  • Loading branch information
myeunee committed Nov 26, 2024
1 parent 3960b55 commit d3d8910
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
21 changes: 20 additions & 1 deletion chapter20/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net/http"

"github.com/myeunee/GolangStudy/chapter20/auth"
"github.com/myeunee/GolangStudy/chapter20/clock"
"github.com/myeunee/GolangStudy/chapter20/config"
"github.com/myeunee/GolangStudy/chapter20/handler"
Expand All @@ -25,7 +26,25 @@ func NewMux(ctx context.Context, cfg *config.Config) (http.Handler, func(), erro
if err != nil {
return nil, cleanup, err
}
r := store.Repository{Clocker: clock.RealClocker{}}
clocker := clock.RealClocker{}
r := store.Repository{Clocker: clocker}
rcli, err := store.NewKVS(ctx, cfg)
if err != nil {
return nil, cleanup, err
}
jwter, err := auth.NewJWTer(rcli, clocker)
if err != nil {
return nil, cleanup, err
}
l := &handler.Login{
Service: &service.Login{
DB: db,
Repo: &r,
TokenGenerator: jwter,
},
Validator: v,
}
mux.Post("/login", l.ServeHTTP)
at := &handler.AddTask{
Service: &service.AddTask{DB: db, Repo: &r},
Validator: v,
Expand Down
13 changes: 13 additions & 0 deletions chapter20/store/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ name, password, role, created, modified
u.ID = entity.UserID(id)
return nil
}

func (r *Repository) GetUser(
ctx context.Context, db Queryer, name string,
) (*entity.User, error) {
u := &entity.User{}
sql := `SELECT
id, name, password, role, created, modified
FROM user WHERE name = ?`
if err := db.GetContext(ctx, u, sql, name); err != nil {
return nil, err
}
return u, nil
}
Binary file modified chapter20/tmp/main
Binary file not shown.

0 comments on commit d3d8910

Please sign in to comment.