@@SantiagoPerez-il8tj in my personal preference and opinion, I usually rely on both documentation and learning from YT video, along side that, shouldn't matter which medium you prefer, as long as you're able to effective learn thats all that matters, besides everyone has their own different learning style.
37:20 I got an explanation from chatgpt which absolutely cool. books = append(books[:index], books[index+1:]...) This line removes the matched item from the books slice. It does this by "slicing" around the current index: books[:index] is the part of the slice up to (but not including) the element at index. books[index+1:] is the part of the slice after index. append(books[:index], books[index+1:]...) combines both parts, effectively skipping the element at index.
Thank you Brad. I watch your 1hr 30min intro to golang. And now I am watching this. It has brought me a long way. Here is a closure function to generate unique ids instead of the random. //closure function to generate ids for book func IdGenerator() func() int { id := 1 return func() int { id++ return id } } var IdGen func() int = IdGenerator() Thats how far I have come. Keep on.
This greatest tutorial I've ever seen and I've seen some bad ones can't understand voice, guys going hundred miles hour leaving shit out. You are truly gifted
You don't really need to import all the packages at the beginning, also you don't need to align types in your struct with tabs, go fmt does it for you which runs automatically when you save your code in vscode. You may have noticed (I did) that your extra unused imports went away as you saved your real code (not the hello world one) for first time. Anyway you said it in the beginning that you are new to golang so not to worry, it happens. Overall a good video for golang newbies.
I just want to say that you're the AWESOME! I really appreciate you're work, i think you're the best programming instructor on internet. To do all this tutorials for free, just priceless, GOD bless you! I learned so many things with you, thank you so much! Please never stop this videos, i study Computer Science at university, but i learned pretty much with you than at university:)
Thanks again Brad. Another really good tutorial. Go is by far my favourite language just now and for the purpose of serving json apis in this manner is highly performant. You've shown how to get this done efficiently and explain how to get there in a very clear and easy to understand way.
So you mention that you don't fully grasp slices when explaining the delete function, which may have changed by now, but for anyone watching, the gist of that delete line is: - list[beginning:end] is a sublist of list from the indexes beginning to end - so list[1:3] on a list like {1, 2, 3, 4} would give you a new list with the elements 1 and 2 (so, {2,3}) of the original one (remember that indexes start at 0, and also the ending point is excluded from the sublist) - If you don't put any index, the starting point defaults to 0, and the ending point defaults to the length of the list - So books[:index] is "all books from the beginning to the index we got in the request" (excluding the last one of the sublist: the book we are deleting) - And books[index+1:] is "all books from the book following the one we got from the request till the end" - And then you're stitching these 2 sublists back together with append - omitting the book you are deleting
This language looks so clean / so smooth and beatiful defintly going to try this. thank you brad for introducing me to something else besides javascript. I like what I'm seeing. As soon as you are ready for a full course in Udemy I will buy this course looking forward to more Go !
Thank you sir. I have been programming professionally since 1999 in a multitude of different programming languages but mostly in the areas of web development and server Administration so PHP python Perl Ruby Etc. I recently started delving into Dart 2 and golang. Honestly go looked pretty easy but there were a lot of little things that I didn't quite understand and I really just want to jump right in and I feel like this video hit on some of the key things that I questioned but wasn't sure how to quickly learn through the tutorials and example code scattered around the web. I learn by example generally and usually by browsing code. I very much appreciate you taking the time to make this video tutorial it helped me grasp this quickly. Thank you.
32:53 When in tutorial someone says dont use this in production then we expect that you suggest what will be a better approach in just brief. Because we want to learn best practice in coding.
This is something that you would let the database handle. The database can generate a unique identifier so that you're sure that you won't have two items that have the same ID.
GO is my first programming language at all an i like it a lot. I really would like to see some tutorial of fully functional CRUD application, like - Customers -> Orders, with MySQL and Web Components (not Polymer).
For the updating Book, we can just replace the item as below func updateBook(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") params := mux.Vars(r) for i, item := range books { if item.ID == params["id"] { var book Book _ = json.NewDecoder(r.Body).Decode(&book) book.ID = item.ID books[i] = book } } json.NewEncoder(w).Encode(books) }
As a somewhat newbie to go I highly recommend you do a course on go. I am almost through with the book "the go programming language" and it is a very efficient language
My notes so far: 1:30 - Were going to use http 2:30 - actually, were jumping straight to using a third party router instead of using the standard http lib 3:48 - $ = "money sign" 👌
What are you comparing with for the 10x faster perf? If you use `graphql-jit` then you can get more perf out of JS. But if you really need the perf then Go isn't the right tool, you're better off with something like Rust.
I love how this is pretty similiar with Node.Js (Express)'s Webservice. Thankyou for sharing Brad! I feel related to you because I'm a JavaScript boy and wanted to learn this Go language
I am sure people are still waiting on that course I really hope that it comes out. It would be really great. I wasn't able to find anyone for me on udemy that explains GO.
@31:20 The reason it disappears is because if you import a package and don't use it, the code will not compile. The extension just helps you along with the process :)
Also, the deleteBook function is appending two slices. The first slice goes up to (not including) the index and the second slice starts after the index. Hence, the index is not included in the new array. This is equivalent to deleting it. Probably, this is what higher-level languages do under the hood.
Tip for new beginners: The first 10 minutes hazzle of creating a Go file and package and imports could be avoided by just using Goland. The autoimport feature saves you for manually typing every package
I wish that I knew Go at the beginning of college, I honestly don't know how I ever made a Rest like api with goddamn PHP. Go is by far my favorite language ever since I discovered it
Great video, thank you very much! Regarding the append(books[:index], books[index+1]...) syntax this may be more familiar to people that comes from python! It basically replaces the books slice with itself but up until "index" (first argument) and from "index+1" to the end of the slice (second argument). The dotdotdot is the same as the * operator when put before lists in python. It basically "unwraps" the list (in this case the slice) into single elements and gives them to the append function as if they were comma separated (this is sort of a workaround to feed the append function when you have already other data stored in other slices (or arrays)) Hope this helps =) EDIT: missing "other data" in the last line
I second all the remarks on the excellency that you brought! Well done my friend! One thing that wasn't clear was the usage of the _ operator(the blank identifier) in the following line: `_ = json.newDecoder(r.body).Decode(&book)` (line 53, minute 33:33) however, it was a delightful opportunity to learn through inference fascinating things about this language! After looking up the decode function i see it returns an error and the blank identifier allows execution without having to worry about catching said error.. so that is why a seemingly mutating function requires an assignment of void(the blank identifier) sending error handling to oblivion.. that's my inference i suspect it wouldn't compile otherwise... i was wondering why a void mutating function had an assignment precede it in the first place.. again, well done and thank you! I wish you the best in your future endeavors!
After spinning this project up and removing the `_ =` from the line, it built and executed just fine, so my inference was wrong.. So? Why did you add that? Seems like `json.newDecoder(r.body).Decode(&book)` does exactly the same thing.. Was it because you were unsure of what was returned from this functions in the first place and just wanted to be extra careful? O! I think I know why it doesn't cause a compile time error and my test-case(simple creating a book with the correct parameters) BECAUSE IT IS A RUNTIME ERROR!!! Duh! .. UPDATE: nope that isn't it, I couldn't break the code.. Perhaps you thought that since you couldn't anticipate what might cause the error to be thrown and didn't care to handle that exceptional case, you would just "be safe" and cover the unknown(through the use of this blank identifier, which I am still assuming basically mean if anything is returned send it to oblivion)? Ahh... I am at a loss, this is something like my first week at Go programming for me though, so I am going to stop beating myself up... BUT PLEASE LET ME KNOW, thanks :)
Very good tutorial, thank you. In the update function you delete the item and create a new one to append on the end. Instead of rewriting this functionality, would you just be able to call the 2 functions that you already created for delete and create? Also, if you wanted to do a proper update, you could just modify the properties of the book at books[index] (ex. books[index].Title = book.Title) or replace the whole book with the new one (ex. books[index] = book (you would have to make sure the ID is still correct with this one tho)).
The update request could simply be: books[index] = updatedBook, and with this solution updatedBook.ID needs to be made the same as book.ID, but that's a minor detail.
Why did you decide to capitalize the structs in this project? I mean they worked just fine for me in lowercase and (afaik) having them start with an uppercase letter would only export them (which wouldn't be needed in this small project).
You could test your API using REST Client (an extension in vscode) directly from vscode instead of dowloading, installing and filling the fields in postman. Link: marketplace.visualstudio.com/items?itemName=humao.rest-client
Good tutorial. But explanations are still missing for beginners like me such as "Why should a variable in a struct begin with an upper case?" ( to be an exported variable, otherwise it wouldn't work. I wasted alot of time looking for why it wasn't working ), you should add an error handler in case that the json request isn't what we're expecting ( bad/missing attributes ). What does the underscore in the loop function mean ? And why are you using an underscore to decode a json ?
Hey Brad, I was successful with the get all books but on moving on to get single book, the postman returned a blank response, saying "405 Method Not Found." I went ahead to create book and it went through but on running Get book, it returned 404 not found. Please help on what I can do.
Thanks Brad, I followed your tutorial and cannot compile, the error message is "go build runtime/cgo: copying /Users/shuaishao/Library/Caches/go-build/a1/a195b901aae0a10a5971c762413083aa8b422336860f68ba78816eca576ae573-d: open /usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied", you have any idea?
Would be nice to see an example of a patch request using json.Unmarshall. Additionally, your updateBook could be as simple as books[index] = book (with book being the json decoded r.Body).
If I'm not wrong, embedding a struct within another struct is called composition? I really love go. Been learning for a few weeks now and its been really amazing
Great tutorial.I appreciate the way you are able to simplify the process down and make it easy for people to understand. Are you able to share your VSCode theme and color scheme modifications?
4 роки тому
It is very simple, very clear video thank you so much!
just a question for clarificaiton if you can... When you are doing the update book, right after your if statement when you do "books = append(books[:index], books[index+1]...) is this basically just removing your book from the mock database, then re-adding it after the necessary updates have been made down below? I noticed the delete method does just that part and I was wondering if that is why your update works. basically using the 0 index of the slice to find where in the books it is, as the specific book due to 0 index would always be index -1 in the mock database, deleting them, then readding it ensuring the ID integrity using the book.ID = params["id"]. you said in the course you didn't know why this works and I really just wanted to understand it
when you getting a lot of books will a for loop be exspensive ? what if you use a array and id value is the interger of the array value so you get no for loop ?
This is a nice introduction. But is it common in golang to define/declare model within this same file? Should it not be defined separately in something like a model package, so that it can be re-used? Same with the function definitions too. Shouldn’t they be declared in another file/package and invoked in main.go?
For the updateBook function, you can also omit the last line, json.NewEncoder(w).Encode(books), as it would return a list of all the books if the book ID is not found.
Hey! This is awesome video! In the video, there were already two data initially. However, when I tried with no initial mock data, when I did r.HandleFunc("/api/books",getBooks).Methods("GET"), it returns null and not empty slice [ ]. How to make it returns [ ] on the browser even though initially theres no data at all? Thank you!
Hi traversy, How do you deploy this go project in Linux or windows server? I am trying to deploy it in azure app service but not understanding how to do it?
Good video Brad 👌 I must say, Go is seriously shorter to write than what I'm used to, but I can't say it's very intuitive if you know what I mean... Slice, mux, struct, func, _. ? 😆 Give me spring boot any day
To configure the Go extension for VS Code to not remove unused packages, disable formatOnSave in your User Settings: "[go]": { "editor.insertSpaces": false, "editor.formatOnSave": false }
For viewers at 32:45 - line 54 can be better written as: `book.ID = strconv.Itoa(len(books)+1) ` This is incrementing the length of books by 1 as a new id..
Brad! You are genius! Looking forward to your Golang course. You definitely have a gift to share your knowledge.
I'd 100% buy an intermediate/advanced Golang course from you.
all those YT "lessons" are just reading out documentation. u gotta be rly lazy
@@quantum-t But not all of them explain good
@@SantiagoPerez-il8tj they literally do
@@SantiagoPerez-il8tj in my personal preference and opinion, I usually rely on both documentation and learning from YT video, along side that, shouldn't matter which medium you prefer, as long as you're able to effective learn thats all that matters, besides everyone has their own different learning style.
"I'm actually thinking of doing a course on it."
YES!!!!
Is the course out?
he never did! :'D
ua-cam.com/video/SqrbIlUwR0U/v-deo.html
37:20 I got an explanation from chatgpt which absolutely cool.
books = append(books[:index],
books[index+1:]...)
This line removes the matched item from the books slice. It does this by "slicing" around the current index:
books[:index] is the part of the slice up to (but not including) the element at index.
books[index+1:] is the part of the slice after index.
append(books[:index], books[index+1:]...) combines both parts, effectively skipping the element at index.
Thank you Brad. I watch your 1hr 30min intro to golang. And now I am watching this. It has brought me a long way. Here is a closure function to generate unique ids instead of the random.
//closure function to generate ids for book
func IdGenerator() func() int {
id := 1
return func() int {
id++
return id
}
}
var IdGen func() int = IdGenerator()
Thats how far I have come. Keep on.
This greatest tutorial I've ever seen and I've seen some bad ones can't understand voice, guys going hundred miles hour leaving shit out. You are truly gifted
You don't really need to import all the packages at the beginning, also you don't need to align types in your struct with tabs, go fmt does it for you which runs automatically when you save your code in vscode. You may have noticed (I did) that your extra unused imports went away as you saved your real code (not the hello world one) for first time. Anyway you said it in the beginning that you are new to golang so not to worry, it happens. Overall a good video for golang newbies.
I just want to say that you're the AWESOME! I really appreciate you're work, i think you're the best programming instructor on internet. To do all this tutorials for free, just priceless, GOD bless you! I learned so many things with you, thank you so much! Please never stop this videos, i study Computer Science at university, but i learned pretty much with you than at university:)
Thanks again Brad. Another really good tutorial. Go is by far my favourite language just now and for the purpose of serving json apis in this manner is highly performant. You've shown how to get this done efficiently and explain how to get there in a very clear and easy to understand way.
This is the most elegant language i've ever seen with 80 lines of code you've made a rest api, looking forward for more go-lang content :)
it wasn't long, nicely paced and controlled depth of details.
Great video.
finally got my head around it a little.
A second part would be awesomeeee. Thank you so much for your help! This helped a lot to start learning some things for a new job I started! :)
This was a terrific intro to Go and a basic REST api, please do more!
So you mention that you don't fully grasp slices when explaining the delete function, which may have changed by now, but for anyone watching, the gist of that delete line is:
- list[beginning:end] is a sublist of list from the indexes beginning to end
- so list[1:3] on a list like {1, 2, 3, 4} would give you a new list with the elements 1 and 2 (so, {2,3}) of the original one (remember that indexes start at 0, and also the ending point is excluded from the sublist)
- If you don't put any index, the starting point defaults to 0, and the ending point defaults to the length of the list
- So books[:index] is "all books from the beginning to the index we got in the request" (excluding the last one of the sublist: the book we are deleting)
- And books[index+1:] is "all books from the book following the one we got from the request till the end"
- And then you're stitching these 2 sublists back together with append - omitting the book you are deleting
This language looks so clean / so smooth and beatiful defintly going to try this. thank you brad for introducing me to something else besides javascript. I like what I'm seeing. As soon as you are ready for a full course in Udemy I will buy this course looking forward to more Go !
this
Thank you sir. I have been programming professionally since 1999 in a multitude of different programming languages but mostly in the areas of web development and server Administration so PHP python Perl Ruby Etc. I recently started delving into Dart 2 and golang. Honestly go looked pretty easy but there were a lot of little things that I didn't quite understand and I really just want to jump right in and I feel like this video hit on some of the key things that I questioned but wasn't sure how to quickly learn through the tutorials and example code scattered around the web. I learn by example generally and usually by browsing code. I very much appreciate you taking the time to make this video tutorial it helped me grasp this quickly. Thank you.
32:53
When in tutorial someone says dont use this in production then we expect that you suggest what will be a better approach in just brief. Because we want to learn best practice in coding.
This is something that you would let the database handle. The database can generate a unique identifier so that you're sure that you won't have two items that have the same ID.
you should look into "github.com/google/uuid" package
Hi Brad, could you please create more videos on Golang? I would be very grateful. Your time is appreciated.
GO is my first programming language at all an i like it a lot. I really would like to see some tutorial of fully functional CRUD application, like - Customers -> Orders, with MySQL and Web Components (not Polymer).
Same here
Good choice!
I'm doing a React app with a Golang back-end. I'm no expert though... That's like my first full-stack app.
Alright after 3 years , still one of the best source to learning GO! Tyvm 🍻
This was excellent Brad. The syntax for Goland is very appealing and I look forward to more tutorials.
For the updating Book, we can just replace the item as below
func updateBook(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
params := mux.Vars(r)
for i, item := range books {
if item.ID == params["id"] {
var book Book
_ = json.NewDecoder(r.Body).Decode(&book)
book.ID = item.ID
books[i] = book
}
}
json.NewEncoder(w).Encode(books)
}
Great brother, and break the loop could be the best practice I think
As a somewhat newbie to go I highly recommend you do a course on go. I am almost through with the book "the go programming language" and it is a very efficient language
My notes so far:
1:30 - Were going to use http
2:30 - actually, were jumping straight to using a third party router instead of using the standard http lib
3:48 - $ = "money sign"
👌
Brad please make a Go course! Would love to learn more about Go especially from you
Thanks so much for your course! Can't wait for Part 2 and maybe Angular as a frontend !
I'd love to see more videos on Go. A course on it would be great!
It's time to make a course on Google RPC(remote procedure call) framework which is 10x faster than GraphQL. Also, implement it with Golang.
where'd you get the 10x faster figure?
What are you comparing with for the 10x faster perf? If you use `graphql-jit` then you can get more perf out of JS.
But if you really need the perf then Go isn't the right tool, you're better off with something like Rust.
Brad love your tutorials pls make more in go!
it's really hard to find more videos in golang nowadays
For unique IDs in the scope of this exercise, I would use UUID instead. It should be safe and should not have collisions in a limited space.
Nice to see some Go here, hopefully more to follow :P
Definitely, I love it
It’s really similar to python but with types
I love golang. It's nice to see a tutorial about it in this channel. Hopefully there will be much more.
I love how this is pretty similiar with Node.Js (Express)'s Webservice. Thankyou for sharing Brad! I feel related to you because I'm a JavaScript boy and wanted to learn this Go language
I am sure people are still waiting on that course I really hope that it comes out. It would be really great. I wasn't able to find anyone for me on udemy that explains GO.
@31:20 The reason it disappears is because if you import a package and don't use it, the code will not compile. The extension just helps you along with the process :)
Looking forward for the next video where the database is implemented. Great tut, subscribed!
Not an indian tutorial, but very awesome. Thank you very much!
Also, the deleteBook function is appending two slices. The first slice goes up to (not including) the index and the second slice starts after the index. Hence, the index is not included in the new array. This is equivalent to deleting it. Probably, this is what higher-level languages do under the hood.
Tip for new beginners: The first 10 minutes hazzle of creating a Go file and package and imports could be avoided by just using Goland. The autoimport feature saves you for manually typing every package
Or just the Go extension in vscode?
Great video! Looking forward to the full-stack implementation with the database.
this is the best go tutorial for bignner ever I seen....
I would really love to see a course from you on Golang. You're great at explaining things.
I wish that I knew Go at the beginning of college, I honestly don't know how I ever made a Rest like api with goddamn PHP. Go is by far my favorite language ever since I discovered it
Great video, thank you very much!
Regarding the append(books[:index], books[index+1]...) syntax this may be more familiar to people that comes from python! It basically replaces the books slice with itself but up until "index" (first argument) and from "index+1" to the end of the slice (second argument).
The dotdotdot is the same as the * operator when put before lists in python. It basically "unwraps" the list (in this case the slice) into single elements and gives them to the append function as if they were comma separated (this is sort of a workaround to feed the append function when you have already other data stored in other slices (or arrays))
Hope this helps =)
EDIT: missing "other data" in the last line
I second all the remarks on the excellency that you brought! Well done my friend! One thing that wasn't clear was the usage of the _ operator(the blank identifier) in the following line:
`_ = json.newDecoder(r.body).Decode(&book)` (line 53, minute 33:33)
however, it was a delightful opportunity to learn through inference fascinating things about this language! After looking up the decode function i see it returns an error and the blank identifier allows execution without having to worry about catching said error.. so that is why a seemingly mutating function requires an assignment of void(the blank identifier) sending error handling to oblivion.. that's my inference i suspect it wouldn't compile otherwise... i was wondering why a void mutating function had an assignment precede it in the first place.. again, well done and thank you! I wish you the best in your future endeavors!
After spinning this project up and removing the `_ =` from the line, it built and executed just fine, so my inference was wrong.. So? Why did you add that? Seems like `json.newDecoder(r.body).Decode(&book)` does exactly the same thing.. Was it because you were unsure of what was returned from this functions in the first place and just wanted to be extra careful? O! I think I know why it doesn't cause a compile time error and my test-case(simple creating a book with the correct parameters) BECAUSE IT IS A RUNTIME ERROR!!! Duh! .. UPDATE: nope that isn't it, I couldn't break the code.. Perhaps you thought that since you couldn't anticipate what might cause the error to be thrown and didn't care to handle that exceptional case, you would just "be safe" and cover the unknown(through the use of this blank identifier, which I am still assuming basically mean if anything is returned send it to oblivion)? Ahh... I am at a loss, this is something like my first week at Go programming for me though, so I am going to stop beating myself up... BUT PLEASE LET ME KNOW, thanks :)
I can't stress how much this was helpful!!
Mr.Brad, do you have a plan for a paid course on the Go with React js? Kindly create a course. We would highly appreciate your effort.
Very good tutorial, thank you. In the update function you delete the item and create a new one to append on the end. Instead of rewriting this functionality, would you just be able to call the 2 functions that you already created for delete and create? Also, if you wanted to do a proper update, you could just modify the properties of the book at books[index] (ex. books[index].Title = book.Title) or replace the whole book with the new one (ex. books[index] = book (you would have to make sure the ID is still correct with this one tho)).
Finally! Thanks so much for doing this, pls do a course on this!
The update request could simply be: books[index] = updatedBook, and with this solution updatedBook.ID needs to be made the same as book.ID, but that's a minor detail.
Too cool! Nice video. Would be interessant a video talking about of initial features for beginners in the Go Lang, please!
Hi,
At 29:45 you're returning a single book. How does the &Book{} pick up the correct book? I'm a little confused there
Why did you decide to capitalize the structs in this project? I mean they worked just fine for me in lowercase and (afaik) having them start with an uppercase letter would only export them (which wouldn't be needed in this small project).
It's required to make fields exported for "json" package to work. Refer to this SO answer.
stackoverflow.com/a/50320595/6753606
I was shocked to see this video. THANKS! You are awesome. So is golang
Traversy Media is like a code-gym for developers :)
You could test your API using REST Client (an extension in vscode) directly from vscode instead of dowloading, installing and filling the fields in postman.
Link: marketplace.visualstudio.com/items?itemName=humao.rest-client
Good tutorial. But explanations are still missing for beginners like me such as "Why should a variable in a struct begin with an upper case?" ( to be an exported variable, otherwise it wouldn't work. I wasted alot of time looking for why it wasn't working ), you should add an error handler in case that the json request isn't what we're expecting ( bad/missing attributes ). What does the underscore in the loop function mean ? And why are you using an underscore to decode a json ?
You might want to check out his crash course which is tailored towards beginners: ua-cam.com/video/SqrbIlUwR0U/v-deo.html
Very fast API coding! Excellent idea. Like this techics, thanks you
Looking forward for this course.. Thank you Brad!
Wow. Golang. That's a bold move. I wish I have time to learn it somehow.
Hey Brad, I was successful with the get all books but on moving on to get single book, the postman returned a blank response, saying "405 Method Not Found." I went ahead to create book and it went through but on running Get book, it returned 404 not found. Please help on what I can do.
Hello Brad, please when are you going to do the next phase of this tutorial?
Amazing, very clear neat explanation to get started with GO Rest APIs , Thanks :)
Why did you use .Encode(&Book{}) but not just .Encode(Book{}) on 29:39?
Thanks Brad, I followed your tutorial and cannot compile, the error message is "go build runtime/cgo: copying /Users/shuaishao/Library/Caches/go-build/a1/a195b901aae0a10a5971c762413083aa8b422336860f68ba78816eca576ae573-d: open /usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied", you have any idea?
Loved it! And waiting for the 2nd part with database
Would be nice to see an example of a patch request using json.Unmarshall. Additionally, your updateBook could be as simple as books[index] = book (with book being the json decoded r.Body).
waits patiently for Go Web Development Course
If I'm not wrong, embedding a struct within another struct is called composition? I really love go. Been learning for a few weeks now and its been really amazing
Great tutorial, we're waiting for the second part
this is great ! :) please do a beginner course for go :)
he did
Great tutorial.I appreciate the way you are able to simplify the process down and make it easy for people to understand.
Are you able to share your VSCode theme and color scheme modifications?
It is very simple, very clear video thank you so much!
Thanks for your time my friend !
just a question for clarificaiton if you can...
When you are doing the update book, right after your if statement when you do "books = append(books[:index], books[index+1]...)
is this basically just removing your book from the mock database, then re-adding it after the necessary updates have been made down below?
I noticed the delete method does just that part and I was wondering if that is why your update works. basically using the 0 index of the slice to find where in the books it is, as the specific book due to 0 index would always be index -1 in the mock database, deleting them, then readding it ensuring the ID integrity using the book.ID = params["id"].
you said in the course you didn't know why this works and I really just wanted to understand it
when you getting a lot of books will a for loop be exspensive ?
what if you use a array and id value is the interger of the array value so you get no for loop ?
I waiting for this video for a very long time thanks, brad...
This is a nice introduction. But is it common in golang to define/declare model within this same file? Should it not be defined separately in something like a model package, so that it can be re-used? Same with the function definitions too. Shouldn’t they be declared in another file/package and invoked in main.go?
For the updateBook function, you can also omit the last line, json.NewEncoder(w).Encode(books), as it would return a list of all the books if the book ID is not found.
Actually it returns the book struct with empty values, when not finding the book ID
Nice tutorial! Looking forward for a series
Was wondering whether there is a part 2 and 3 on this video into golang here on youtube?
Thank you Brad! Please make a full Udemy course about Golang for web 🙏
Hey! This is awesome video!
In the video, there were already two data initially. However, when I tried with no initial mock data, when I did r.HandleFunc("/api/books",getBooks).Methods("GET"), it returns null and not empty slice [ ]. How to make it returns [ ] on the browser even though initially theres no data at all? Thank you!
Hi traversy, How do you deploy this go project in Linux or windows server? I am trying to deploy it in azure app service but not understanding how to do it?
Hello Traversy, do you have a golang + vuejs/reactjs course on udemy ?
Very well explained. Enjoyed watching till the end :) thanks!!!
Thx again Brad. What is the theme you are using? Very liked colorful brackets.
@Lucas Farias thx. +rainbow parenthesis extension I guess.
A Full Stack GoLang Course with Angular 4, and any database at all would be awesome!
Nice Tutorial, love go.. its so fast. No overhead
Good video Brad 👌
I must say, Go is seriously shorter to write than what I'm used to, but I can't say it's very intuitive if you know what I mean...
Slice, mux, struct, func, _. ? 😆
Give me spring boot any day
Another approach for update operation:
if item. ID ==params["id"] {
var book Book
_ = json.NewDecoder(r.Body).Decode(&book)
books[i] = book
To configure the Go extension for VS Code to not remove unused packages, disable formatOnSave in your User Settings:
"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": false
}
Better yet, realize that references to a package that has not been imported will be automatically imported by default.
Good video & Thank-You
And provide the complete video of Golang
I’m loving the mern stack videos but any chance we could get a mgrn stack tutorial with Mongodb atlas?
+1
Great explaining ... Good diction, you are the man man :D thank you man, now I understand things much better
Hi, Is the course you were talking about out?
Please post the link if you made a second video on this.. Very Nice Video
Thank you so much sir...this tutorial was fantastic
For viewers at 32:45 - line 54 can be better written as:
`book.ID = strconv.Itoa(len(books)+1) `
This is incrementing the length of books by 1 as a new id..