# I am the Watcher. I am your guide through this vast new twtiverse.
# 
# Usage:
#     https://watcher.sour.is/api/plain/users              View list of users and latest twt date.
#     https://watcher.sour.is/api/plain/twt                View all twts.
#     https://watcher.sour.is/api/plain/mentions?uri=:uri  View all mentions for uri.
#     https://watcher.sour.is/api/plain/conv/:hash         View all twts for a conversation subject.
# 
# Options:
#     uri     Filter to show a specific users twts.
#     offset  Start index for quey.
#     limit   Count of items to return (going back in time).
# 
# twt range = 1 8
# self = https://watcher.sour.is/conv/rpofvqa
@prologic and others may I ask you to review some code? https://git.envs.net/cblte/golang-webapp/releases/tag/0.7 It is not finished yet, but I think I am on a good way. Still needs some polishing. WebDev is actually new to me with all the status codes and stateless things and everything. So feedback would be appreciated. Using Redis because it was easy to setup and to implement. Actually want to use SQLite or something else, but Redis seems to do the job for now.
Hello @carsten,
I'll say that :
- everything being in the main is bad
- the handler structure can be better done, more structured and separating the http part, from the real business part (some interfaces may help)
- rclient should be injected.
- there is no env variable management
- there is no unit tests (that one you know)
- there is no metrics (if it was a professional project I 'll be waiting for those)
Hello @carsten,
I'll say that :
- everything being in the main is bad
- the handler structure can be better done, more structured and separating the http part, from the real business part (some interfaces may help)
- rclient should be injected.
- there is no env variable management / config management (viper is good for that)
- there is no unit tests (that one you know)
- there is no metrics (if it was a professional project I 'll be waiting for those)
- gitignore should maybe have golang-webapp on it.
Hello @carsten,
I'll say that :
- everything being in the main is bad
- the handler structure can be better, more structured and separating the http part, from the real business part (some interfaces may help)
- rclient should be injected.
- there is no env variable management / config management (viper is good for that)
- there is no unit tests (that one you know)
- there is no metrics (if it was a professional project I 'll be waiting for those)
- gitignore should maybe have golang-webapp on it.
@tkanos's comments are all good points. I actually think the code is actually pretty good really. One thing you can also do to enhance deployment(s) is the use of the embed package to embed the static assets and templates. Freel free to borrow/slash/steal code from yarnd 😅
@tkanos's comments are all good points. I actually think the code is actually pretty good really. One thing you can also do to enhance deployment(s) is the use of the embed package to embed the static assets and templates. Freel free to borrow/slash/steal code from yarnd 😅
@prologic Thanks. This embed package is something I was looking for. Have it on my list, but did not get that far
@carsten I only had a quick look and this is all in no particular order:

1. I'm sure go fmt would add a space after the comment marker //.
2. Go doc strings are supposed to start with the name of the variable etc (I'm not a fan of this, either).
3. Sometimes log.SetPrefix(…) ends with a space, sometimes not.
4. Some messages start capital, some don't.
5. Typo: occurred with double r.
6. On lots of errors no appropriate status code is set.
7. Some err can be scoped in the if like that: if err := foo(); err != nil { … }
8. The <title>s could be improved.
9. I have no idea about redis, but rclient.Set("user:"+username, …) looks suspicious to me and reminds me of SQL injections.
10.
o
cookie, err := r.Cookie("session_token")
if err != nil {
    if err == http.ErrNoCookie { … return }
}

doesn't look complete. Also handle other errors? Or simplify without nil check.