Programming

99 Artikel tersedia

01 RESTful Introduction to Golang

01 RESTful Introduction to Golang

Introduction to RESTFul API

Quoted from the amazon website, RESTful API is an interface used by two computer systems to securely exchange information over the internet. Most business applications must communicate with other internal and third-party applications to perform various tasks. For example, to generate monthly payslips, your internal accounts system must share data with your customers’ banking systems to automate billing and communicate with internal time and attendance applications. RESTful APIs support this exchange of information because they follow software communication standards that are secure, reliable and efficient.

09 How To Use Streaming Encoder

09 How To Use Streaming Encoder

Introduction to Stream Encoders

Apart from JSON Decoder, this JSON package can also support Encoder which is used directly JSON into io.Writer. So that way we don’t need to store the JSON data first into a string or []byte variable, so we can just write it directly into io.Writer.

08 How To Use Streaming Decoder

08 How To Use Streaming Decoder

Introduction to Stream Decoder

In the previous article, we studied the JSON package by using conversion of JSON data which was already in the form of variables and string data or we used []byte. Sometimes the JSON data comes from input in the form of io.Reader, which can be in the form of a file, network or request body. So we could just read all the data first, then store it in a variable and then convert it from JSON, but we don’t need to do this because the JSON package has a feature for reading data from Stream.

07 How To Use Maps

07 How To Use Maps

Map Use

When we use JSON we sometimes encounter cases of dynamic JSON data, which means that the attributes formed by JSON are uncertain, can increase or decrease and are not even fixed. So in cases like this, if we unmarshal using Struct, it will be difficult because in the struct we have to define all the attributes.

06 How to know JSON Tags

06 How to know JSON Tags

Introduction to JSON Tags

By default, if we create a struct and marshal it, it will be mapped according to the same attribute name and is case sensitive. So what if we want to differentiate the style between naming attributes in structs and those converted into JSON? For example, in structs we use PascalCase but in JSON we want to use snake_case. To support this, the json package supports Tags Reflection, namely tags that can adjust the Json name which we will later convert into JSON so that the tribute in the struct will be converted according to the name into JSON.

05 How to know JSON Array

05 How to know JSON Array

Introduction to JSON Arrays

Apart from JSON in Object form, usually in JSON we can also use the Array data type. Actually, JSON arrays are similar to those in JavaScript where there are primitive data types or complex data types such as object arrays.

04 How to know Decode JSON

04 How to know Decode JSON

Introduction to JSON Decoding

In the previous article we learned to encode JSON and how to create a JSON object, so next we will learn how to translate JSON objects into struct objects in Golang. We often call this conversion from JSON into a Golang struct object as decode.

03 How to know JSON Object

03 How to know JSON Object

Introduction to JSON Objects

In the previous article we studied encoding data such as string, number, boolean and other primitive types. But there is one case in the unit test which is made in the form of a struct object. So, this time we will study the objects of JSON in more depth. JSON data is in the form of objects and arrays, while the values can be objects again or directly data with other primitive types.

02 Encode JSON

02 Encode JSON

Introduction to JSON Encoding

The Golang language already provides functions for JSON data conversion needs, namely we can use this function

01 Introduction Package

01 Introduction Package

Introduction to JSON

JSON stands for JavaScript Object Notation which is a data format structure that looks like Object from JavaScript. JSON is the most widely used data format currently for creating RESTful APIs. All languages can use the JSON format because it can become a standard format for communication between services even if they use different languages. For example, one service uses Golang and another service uses Java, so that it can communicate well it needs the same format, namely JSON, which can standardize the format of the two languages in our service. You can visit https://json.org/json-en.html if you want to learn more.

08 Create Middleware Router

08 Create Middleware Router

Understanding Middleware

HttpRouter is a library for creating an http router, it doesn’t have any other features apart from a router and this router is an implementation of the default http.Handler from Golang itself so that to create middleware we can create it ourselves as we have created in the previous Golang Web post, namely HTTP Middleware.

07 Handle Not Allowed Method

07 Handle Not Allowed Method

Understanding Method Not Allowed

When we use ServerMux, we cannot determine what HTTP Method we will use in the Handler. However, on the router that we are using, we can determine what HTTP method we want to use so that the client will send the appropriate method to the router that we have specified. If it does not comply with the provisions on the Router, a Method Not Allowed error will occur.