다른 화면에서도 isAdmin 함수로 관리자에게만 노출할 기능을 제한해 보자.
▼ app/views/Post/Index.html
{{set . “title” “All Posts”}} {{template “header.html” .}} {{$currentUser := .currentUser}} <table class=“table”> <thead> <tr> <th>#</th> <th>Title</th> <th>Created at</th> <th>Updated at</th> </tr> </thead> <tbody> {{range .posts}} <tr> <th scope=“row”>{{.Id}}</th> <td>{{.Title}}</td> <td><time>{{formatDate .CreatedAt}}</time></td> <td><time>{{formatDate .UpdatedAt}}</time></td> <td><a href=”{{url “Post.Show” .Id}}”>Show</a></td> {{if isAdmin $currentUser }} <td><a href=”{{url “Post.Edit” .Id}}”>Edit</a></td> <td><a href=”{{url “Post.Destroy” .Id}}”>Destroy</a></td> {{end}} </tr> {{end}} </tbody> </table> {{if isAdmin .currentUser }} <p><a href=”{{url “Post.New” }}”>New Post</a></p> {{end}} {{template “footer.html” .}}