kennygrant / gohackernews

Golang News - curated links about the Go programming language
https://golangnews.com
MIT License
282 stars 42 forks source link

Several problems in the installation #28

Closed spearous closed 6 years ago

spearous commented 7 years ago

it is not clear which folder do you run those command. after running "go get -u github.com/kennygrant/gohackernews" from "/home/ec2-user"

  1. i guess, i have to change to the folder where "server.go" located. however, i found there were several folders containing this file. So which folder do I suppose to run "go run server.go"?

  2. did you jump over steps between "go get -u ..." and "go run server.go"? I tried "go build" at the level of "/home/ec2-user/go/src/github.com/kennygrant/gohackernews", Then i tried "go run-server.go" in "/home/ec2-user/go/src/github.com/kennygrant/gohackernews" but it didn't work.

Error: [ec2-user@ip-172-31-31-144 gohackernews]$ go run server.go

[ec2-user@ip-172-31-31-144 gohackernews]$ go run server.go 2017-06-28:14:41:37 Starting server port:3000 #info 2017-06-28:14:41:37 Compiling Asssets in dev mode #info 2017-06-28:14:41:37 a:unable to compile assets error:open public/assets/scripts/app-a5f99514f9bdcea7a778e2fcfeb6aa29a8cf1b4d.min.js: no such file or directory #fatal 2017-06-28:14:41:37 Finished loading assets in 49.15507ms #info 2017-06-28:14:41:37 Finished loading templates in 3.932678ms #info 2017-06-28:14:41:37 unable to read database db:gohackernews_development error:pq: Ident authentication failed for user "gohackernews_server" #fatal exit status 1

it seems a database related error. I have installed postgresql 9.5 succefully. do i suppose to create some user/database/table for golangnews to use?

kennygrant commented 7 years ago

Yes you need to create the database before running the app. If you look in fragmenta.json you should see the database required. You also need some tables, though it should attempt to bootstrap. If you look in db/migrate you should find some migrations to be run on the db before running the app the first time (to set up initial tables).

It's easier to run it first time with the fragmenta tool as that handles the setup for you, though it can be run without this using simple go run server.go if you prefer.

spearous commented 7 years ago

Hi, i think i prefer "go run" for now but may change to use fragmenta if "go run" turned out to be too much work.

I basically figured them out.....setup 3 tables as in the /secret/fragmenta.json. Now i came to the point where it told me some *.png is missing and the following message:

"src/stories/actions/home.go:45 Error querying database for rows: pq: relation "stories" does not exist QUERY: &{stories id SELECT "stories"." FROM "stories" WHERE (points >0) ORDER BY rank desc.................................."

I captured my front page and attach the picture here. Hope you can take a look to help me out, Thanks!!

""

frontpage

kennygrant commented 7 years ago

So I think you now have a database, but you need to create the tables as this error message is telling you the stories table doesn't exist. If you look in db/migrate, do you see an sql file in there? You should see a file called Create-Tables - make sure it references the tables in your secrets file (db and db user), and then run it against your local db, then you should hopefully be up and running.

https://github.com/kennygrant/gohackernews/blob/master/db/migrate/Create-Tables.sql.tmpl

Looks like you're also missing the search icon top right, that must be the missing png. I've fixed the gitignore so that file is now in the repo. Thanks for letting me know. So you can pull that down at least.

I agree the setup needs some work to smooth off rough edges, there are also various templates you'd have to change in order to run the app on another domain, I haven't really focussed on it as I'm pretty busy with paid work at present I'm afraid, so it was released more as an example for reference.

spearous commented 7 years ago

i still have the same errors after creating those tables manually. Maybe the tables cannot be empty?

spearous commented 7 years ago

I also tried fragmenta tool: download and go build fragmenta, then run "framenta server" at "gohackernews" folder. But i end up with the same error. How do you think, if I just do"git clone" of your gohackernews code instead of "go get", then using "go build" and "go run server.go"?

kennygrant commented 7 years ago

Let's focus on the db issue. Running with go run should work just fine and the error is about the db. I don't think it's to do with how you pulled it down.

Might be a permissions issue with the database. Perhaps try using the server credentials (in secrets/fragmenta.json) to log into psql to check that it will let you see those tables:

psql -U myuser -P mypass

The issue I'm thinking of is something like this one:

https://stackoverflow.com/questions/7758533/postgresql-database-owner-cant-access-database-no-relations-found#7758860

spearous commented 7 years ago

i logged in from the command line using "psql -U username -P password" and used "\dn+" to check like what they did in the link you quoted. And my result showed correct privileges. I also attach my result here.

I tried to do the query operations as in the error message from the command line, and there are no returned results (as my second attachment shows). I guess this is because tables are empty. Can this be the problem?

result

result2

spearous commented 7 years ago

Just in case, here is my pg_hba.conf file: result3

kennygrant commented 7 years ago

OK, so we've established the db is accessible, and the tables now exist (as you made them) so the app should see them now.

If you try loading that page again, presumably you don't see the same error message since the relation exists? What does it say now exactly when you try to load that page now you have tables?

If it expects stories you could try creating one in the db to see if that gets you started, but I think you will also need a user with admin privileges so if you deleted that user that could be a problem. There is supposed to be bootstrapping code in there to handle starting without a db and without a user.

spearous commented 7 years ago

I think i got this. I decided to check database step by step from the beginning. Then i found, all of the tables are not belong to the database "gohackernews_development" as they are supposed to. After fixing this, now the frontpage of the website looks fine.

So i re-setup another server to see which step goes wrong. After logging in with the user "postgres" and creating database according to the file under ../db/migrate folder, I should then use "\c hackernews_development" to connect to the database before going to the next step (creating tables). If i didn't connect to the hackernews_development, I would still be able to create tables with no warnings, but tables are then located in the database "postgres". Although later i execute ALTER TABLE commands, and they return no errors, tables are actually still in the database "postgres". It seems to be a basic knowledge but this is the first time i work with database, so ... thank you for your patience!!

I still have a problem with the "sign up" function. after i putting my name/email/passwd and clicking the register button, it returns me an error: "Error:illegal base64 data at input byte 3" as in the attachment. I guess there is still some problem with my database. result

kennygrant commented 6 years ago

Final problem is now fixed. See error #30. Sorry the inscrutable error message didn't help, I've improved that as well to annotate the error, there was a key missing from the newly created secrets file (which I don't check in and is fresh for each install).