demo-apps / go-gin-app Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
html/template: "Index.html" is undefined
Just create routes.go
call from main.go
go build -o app
it's show messages:
./routes.go:6:18: undefined: showIndexPage
request : curl -v --cookie "token=everything_not_empty" localhost:8080
response :
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">
Home
</a>
</div>
<ul class="nav navbar-nav">
<li><a href="/article/create">Create Article</a></li>
<li><a href="/u/logout">Logout</a></li>
</ul>
</div>
</nav>
...
when the cookie token is set, you are seen as an authenticated user even if you are not logged in
this is because of the setUserStatus function
func setUserStatus() gin.HandlerFunc {
return func(c *gin.Context) {
if token, err := c.Cookie("token"); err == nil || token != "" {
c.Set("is_logged_in", true)
} else {
c.Set("is_logged_in", false)
}
}
}
i think a solution could be if tocken, err := c.Cookie("token"); err == nil || isTokenValide(token)
where isTokenValide whould check against a database if the token has been issued
I made a patch and mistakenly sent a revision to the wrong file. Sorry, how to revert it...
The article that goes with this has a typo. When models.article.go is first defined the article struct is missing the backticks:
type article struct {
ID int json:"id"
Title string json:"title"
Content string json:"content"
}
hi
when I run the code it shows
"./handlers.user.go:31:14: too many arguments in call to c.SetCookie
have (string, string, number, string, string, http.SameSite, bool, bool)
want (string, string, int, string, string, bool, bool)
./handlers.user.go:58:13: too many arguments in call to c.SetCookie
have (string, string, number, string, string, http.SameSite, bool, bool)
want (string, string, int, string, string, bool, bool)
./handlers.user.go:80:14: too many arguments in call to c.SetCookie
have (string, string, number, string, string, http.SameSite, bool, bool)
want (string, string, int, string, string, bool, bool)"
could you help sove it ?
After I log in, the options in the menu bar are still register and login
I did go run main.go and i got undefined: initializeRoutes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.