Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
rohithzr3038ygolang is good if you stay away for on jsonapi, which my employer did not understand
-
skonteam9628yam working on a personal project and doing the same thing just to learn golang and improve in node.keep yourself polyglot.
-
rohithzr3038y@grolofson golang can be nice to you if you use it nicely. stay away from things like jsonapi compliance and you will be just fine. proto buffers are also supported but the thing I hate is that it cannot me nil. complicates the matter a lot more
-
@rohithzr what's the best way to handle json api? I was being shown how this lang works and the syntax looks all kinds of weird and I was told that when you run template execute you can only pass on thing in which complicated things I the template when you want to range over different things.. Is this true??
-
rohithzr3038y@grolofson look the best parts are the range func, multi var return
bad part is what you said, so normally (node.js) we send a json as request and on server we place it in a var and use it.
but in go you'll have to define a struct of what exactly will be in json.
but the problem is unlike json things(keys) cannot be null(nil) this causes mayhem.
if req is PATCH /me -d {name:"Rohit"}
and in go struct is
{name string, optionalInfo string}
on parsing it you will get optionalInfo as blank string.
now you won't know if the user wants is to be blank or he just didn't send it -
@rohithzr thanks that was very informative, so could I build say..
Type user struct{
Name string
Age int
}
Type student struct{
Class string
School string
}
Type career struct{
Field string
Position string
}
users := []user{
user{
Name: "John"
Age: 23
}
user{
Name: "Frank"
Age: 42
}
}
students := []student{
student{
Class how do you put array of class here?
school: "UCLA"
class: "welding"
}
student{
school: "Caltech"
class: "CIT-90"
}
}
careers := []career{
career{
field: "medicine"
position: "Dentist"
}
career{
field: "automotive"
position: "engineer"
}
}
How to wrap this so I can pass them?
Data := struct{
User: user[]
Student: student[]
Career: career[]
}
err := tpl.Execute(os.Stdout, Data)
if err != nil {
log.Fatalln(err)
}
How does this help? I'm used to Ruby on Rails and a data base where all variables are always available.
Sorry for the long example/ question.. -
rohithzr3038y@grolofson :D
OK first yea you are fine with the approach. to put array of classes in your student struct use `Class: []string`
then you can send `Class : []string{'1',2'}`
look I did not say that you cannot manage json, I am managing it in my project and we are doing strict jsonapi. so it is an OK approach that you are taking, at least from the first looks -
rohithzr3038y@skonteam well if we unmarshall a json into a struct and in our json there is some column with no data we do not get nil in our struct we get "" quotes empty.
-
@rohithzr well that's just the first way I thought of doing it, but I'm extremely new to go.
What would be the best way to store date to make user profiles?? If I don't know the data before hand Google datastore? -
rohithzr3038y@grolofson store it in string, you do not want anything else. if youbwant manipulation capabilities then you need to parse into Date
-
skonteam9628y@rohithzr yes , and to know if the user sent empty field or didn't send the field at all, you can use string pointers instead of strings in your structs and test for nil , if the field is nil then we did not receive it.
Also you can implement this logic in an unmarshaljson having your struct as a receiver .
PS: am on my phone I all send a gist later.
good luck. -
@skonteam your both helped me more the the hours before trying to wrap my head around it m. Thanks you ++
-
rohithzr3038y@skonteam hmm. OK I'll try it but the problem I face is because we use protobuffers pointers get messed up. will try this though.
-
rohithzr3038y@skonteam i suggested this to my project's "QA" guy.
he is probably right, anyways I was not allowed to do so :P
`Don't get me wrong: your friends is right and it may work. It's after all the strategy used by Kubernetes, Docker & Google Protobuf. But it's also the easiest way to strengthen the memory pressure. A garbage collector has to find position of every pointer and a multiplication like this of the number of pointers is just awful. Also, instead of 4 bytes for a number, you store 12 (8 for the pointer + 4 for the number itself). If it was not enough, each pointer access requires a nil check, meaning branch prediction, meaning it's magnitudes longer than a simple number access.
`
working on two projects.
at the same time.
for 2 different companies
2 completely different scenarios
2 completely different languages
nodejs and golang
undefined
nodejs golang