Re: [go-nuts] imported and not used "errors"

2022-09-27 Thread Kurtis Rader
I find the Gin documentation (and the examples provided by the project) to
be, ahem, lacking in important details. As you can see from the source (
https://github.com/gin-gonic/gin/blob/78dad9d77d8c2d679dedea1fbef5fc8a54372efd/gin.go#L372)
the Run() function returns an error that will tell you binding to port 8080
failed.

While Gin may be a great project (I've never used it) you don't need a
framework like it for your simple example The standard net/http package
works just fine for simple use cases.

On Tue, Sep 27, 2022 at 8:15 AM Conor O'Neill 
wrote:

> I am following a tutorial to great an API in Go with a framework called
> Gin.
>
> I have imported errors and created a function like so;
>
> func createBook(c *gin.Context) {
>
>var newBook book
>
>
>
>if err := c.BindJSON(); err != nil {
>
>return
>
>}
>
>
>
>books = append(books, newBook)
>
>c.IndentedJSON(http.StatusCreated, newBook)
>
> }
>
> func main is as follows;
>
> func main() {
>
>//1.router responsible for handling different routes and diff
> endpoints of API
>
>router := gin.Default()
>
>//2.the route we are handling is /books, ie when u go to
> localhost:8080/books it will call getBooks()function
>
>router.GET("/books", getBooks)
>
>router.POST("/books", createBook)
>
>router.Run("localhost:8080")
>
> }
>
> If i simply ignore the import error I get this;
>
> [GIN-debug] Listening and serving HTTP on localhost:8080
>
> [GIN-debug] [ERROR] listen tcp 127.0.0.1:8080: bind: address already in
> use
>
> I've gone over the tutorial several times and I'm not sure how he isn't
> getting the erros.
>
> On another note are there any good recommendations for documentation to
> create an API without a framework?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAPp9YQWGyicjMrFrMD2yg4Sb%2BLMGFFzGq_aKbRf25iLv2YW1Nw%40mail.gmail.com
> 
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD9NKB%2BE_HXOJD_TFL5AqGEX%3DWP05YjUR%3D%3DCj%3DEjNg2DvQ%40mail.gmail.com.


Re: [go-nuts] imported and not used "errors"

2022-09-27 Thread Steven Hartland
Something is already running on localhost port 8080. use a different port.

On Tue, 27 Sept 2022 at 16:15, Conor O'Neill  wrote:

> I am following a tutorial to great an API in Go with a framework called
> Gin.
>
> I have imported errors and created a function like so;
>
> func createBook(c *gin.Context) {
>
>var newBook book
>
>
>
>if err := c.BindJSON(); err != nil {
>
>return
>
>}
>
>
>
>books = append(books, newBook)
>
>c.IndentedJSON(http.StatusCreated, newBook)
>
> }
>
> func main is as follows;
>
> func main() {
>
>//1.router responsible for handling different routes and diff
> endpoints of API
>
>router := gin.Default()
>
>//2.the route we are handling is /books, ie when u go to
> localhost:8080/books it will call getBooks()function
>
>router.GET("/books", getBooks)
>
>router.POST("/books", createBook)
>
>router.Run("localhost:8080")
>
> }
>
> If i simply ignore the import error I get this;
>
> [GIN-debug] Listening and serving HTTP on localhost:8080
>
> [GIN-debug] [ERROR] listen tcp 127.0.0.1:8080: bind: address already in
> use
>
> I've gone over the tutorial several times and I'm not sure how he isn't
> getting the erros.
>
> On another note are there any good recommendations for documentation to
> create an API without a framework?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAPp9YQWGyicjMrFrMD2yg4Sb%2BLMGFFzGq_aKbRf25iLv2YW1Nw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAHEMsqYXCSdWZTPDGKvgw8he%2Bw0LDOdtPhhDBN%2BRtaCuTwRX4w%40mail.gmail.com.


[go-nuts] imported and not used "errors"

2022-09-27 Thread Conor O'Neill
I am following a tutorial to great an API in Go with a framework called Gin.

I have imported errors and created a function like so;

func createBook(c *gin.Context) {

   var newBook book



   if err := c.BindJSON(); err != nil {

   return

   }



   books = append(books, newBook)

   c.IndentedJSON(http.StatusCreated, newBook)

}

func main is as follows;

func main() {

   //1.router responsible for handling different routes and diff endpoints
of API

   router := gin.Default()

   //2.the route we are handling is /books, ie when u go to
localhost:8080/books it will call getBooks()function

   router.GET("/books", getBooks)

   router.POST("/books", createBook)

   router.Run("localhost:8080")

}

If i simply ignore the import error I get this;

[GIN-debug] Listening and serving HTTP on localhost:8080

[GIN-debug] [ERROR] listen tcp 127.0.0.1:8080: bind: address already in use

I've gone over the tutorial several times and I'm not sure how he isn't
getting the erros.

On another note are there any good recommendations for documentation to
create an API without a framework?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAPp9YQWGyicjMrFrMD2yg4Sb%2BLMGFFzGq_aKbRf25iLv2YW1Nw%40mail.gmail.com.