API authentication questions

Hello,

I wrote a simple token based authentication api and was wondering if someone would want to have
a look at it and see if I made some mistakes or if I could improve some other things.

go-auth

I was also wondering how I could best implement user input validation (I never did that before).

Furthermore I wasn’t sure if I QueryRow prepares the statements and then executes it. Does someone
know that by any chance? Otherwise I would change QueryRow to Prepare and then Exec.

Hi,

Your code works exactly as you wrote it.

I can’t tell you if your code does what you think it should do because there is no documentation telling me what you think it should do or how one is expected to interact with it. There are also no tests.

I was also wondering how I could best implement user input validation (I never did that before).

The “best” way depends on your specific requirements. Start by figuring out what is valid and what is not. Then write some tests, then write some Go that passes the tests.

Furthermore I wasn’t sure if I QueryRow prepares the statements and then executes it. Does someone
know that by any chance? Otherwise I would change QueryRow to Prepare and then Exec.

Does your code with QueryRow work? If yes, leave it alone. If no, fix it.

2 Likes

Did you cosider to use existing well defeined schemes like JWT? There are Go implementations for JWT.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.