Skip to main content
Commonmark migration
Source Link

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

1 Code Generation

#1 Code Generation II think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go. There is also a golang code generation tool called gen.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2.

3 Interfaces

#3 Interfaces II ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

#1 Code Generation I think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go. There is also a golang code generation tool called gen.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2.

#3 Interfaces I ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

1 Code Generation

I think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go. There is also a golang code generation tool called gen.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2.

3 Interfaces

I ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

Added gen: a code generation tool
Source Link
BJR
  • 46
  • 3

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

#1 Code Generation I think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go. There is also a golang code generation tool called gen.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2.

#3 Interfaces I ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

#1 Code Generation I think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2.

#3 Interfaces I ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

#1 Code Generation I think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go. There is also a golang code generation tool called gen.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2.

#3 Interfaces I ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

added 22 characters in body; deleted 2 characters in body
Source Link
BJR
  • 46
  • 3

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

#1 Code Generation I think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2: githubexample2.com/benjamin-thomas/golang-crud-example

#3 Interfaces I ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

#1 Code Generation I think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2: github.com/benjamin-thomas/golang-crud-example

#3 Interfaces I ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

I am also starting out in go (although I used GAE's Datastore), and have spent some time thinking about this. I considered 3 options:

#1 Code Generation I think code generation would be a solid way to approach this solution. There's even a library starting out called streetCURD for PostgreSQL. Code generation seems like a common way to do things in go.

2 Don't Generalize

Depending on how many times you will copy and paste this, it may not be worth for you to generalize it. However, I find that after a few structs I start doubting this route... and others are not generalizing too: Example1. example2.

#3 Interfaces I ended up using interface{} for somethings (like error checking) which you stated you are not interested in. I felt it made the code more readable, which is my goal.

Looking over your code, it seems like you are interested in a method that return a user or a company- depending in the input, interface{} would be the way to go... (pun not intended).

Since I am just starting out, I'd love to see better responses to this question.

Source Link
BJR
  • 46
  • 3
Loading