Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

About


312 Articles Published

Articles by Kiran Kumar Panigrahi

Page 32 of 32

How to detect the content type of a file in Golang?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 01-Nov-2021 7K+ Views

Consider a case where we want to get the content type of a file in Golang for whatever reasons. In order to do that, we must first know how to open the file and read some of its bytes into a buffer slice which we will then pass to a function that will help us in detecting the type of the file.The first step is to open the file whose type we want to check.Open the FileConsider that we have a file named sample.pdf whose contentType is what we want to know. In order to open the file, we need ...

Read More

How to decode JSON into objects in Golang?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 01-Nov-2021 1K+ Views

Suppose we have a JSON that looks like this.{ "name":"Mukul Latiyan", "age":10, "sports":[ "football", "tennis", "cricket" ] }Now, we want to convert this JSON into struct fields which we can access later and maybe iterate over too.In order to do that, we need to first make a struct that will satisfy the fields of the above JSON.The struct shown below will work just fine for the above JSON.type Person struct ...

Read More
Showing 311–312 of 312 articles
« Prev 1 28 29 30 31 32 Next »
Advertisements