Dasar Pemrograman Golang
website·Indexed 33 days ago
https://dasarpemrogramangolang.novalagung.com/A comprehensive guide to Go programming focusing on web development and system integration. Topics include web frameworks like Echo, HTTP/2, gRPC with Protobuf, JWT, LDAP authentication, and secure middleware. It also covers file handling with Excelize, gofpdf, and etree, as well as network protocols including FTP, SSH, SFTP, and SMTP.
What's inside Dasar Pemrograman Golang
- Go (also known as Golang) is an open-source programming language developed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. Introduced to the public in 2009, its design is heavily inspired by the C language, resulting in a syntax similar to C and C++.
Overview of Dasar Pemrograman Golang learning resources
Dasar Pemrograman Golang is a comprehensive learning resource for the Go programming language, consisting of over 160 chapters divided into four progressive categories:
- Basic Go Programming: Covers installation, execution, keywords, pointers, structs, interfaces, reflect, goroutines, channels, and date time.
- Basic Go Web Programming: Focuses on web development fundamentals using only Go's internal APIs (routing, multiplexer, middleware, cookies).
- Advanced Go Programming: Covers advanced topics and popular community libraries, including HTTP, SSL, CORS, CSRF, mail, PDF, Excel, FTP, SSH, WebSockets, Protobuf, and gRPC.
- Case Studies: Provides Proof of Concept (PoC) for solving real-world project problems using Go.
The resource is compatible with Go version 1.26.4.
Overview of the net/http/httptest package
Thenet/http/httptestpackage allows developers to write automated tests for HTTP handlers without needing to run a real server. It provides mock implementations ofhttp.ResponseWriterand*http.Request, enabling isolated, fast testing without network dependencies.Introduction to Go Channels
Channels are thread-safe communication mechanisms used to connect goroutines by transferring data between them. While goroutines execute asynchronously, the act of sending and receiving data via a channel is blocking (synchronous). This means the execution of the program will pause at a channel operation until the data transfer is complete.Use the empty interface (any) to handle dynamic types
In Go, an empty interface is denoted byinterface{}or the aliasany. A variable of this type can hold any value regardless of its type (numeric, string, slice, pointer, etc.), enabling dynamic typing behavior.anyis a type alias forinterface{}and they are functionally identical.var secret any secret = "ethan hunt" secret = []string{"apple", "mango", "banana"} secret = 12.4Understand CORS fundamentals in Go web applications
Cross-Origin Resource Sharing (CORS) is a browser-side security mechanism that determines whether a web application running at one origin (domain) can access resources from a different origin. CORS only affects requests made via JavaScript in a browser; requests made via tools likecurlor from other back-end services are not subject to CORS rules. CORS configuration is implemented on the server side by manipulating specific response headers.Understand the Pipeline Concurrency Pattern in Go
The Pipeline pattern consists of a series of concurrent processes (stages) that are logically connected. Each stage is typically implemented as a goroutine that performs a specific task and passes the result to the next stage via a channel. This approach improves performance by allowing different stages of a process to run in parallel for different data items, maximizing I/O and CPU efficiency. For example, while stage B is archiving the first file, stage A can simultaneously be dumping the second file.Understand JSON Web Token (JWT) Structure
JWT is a JSON standard (RFC 7519) used for access tokens. A JWT consists of three parts encoded and cryptographically signed:
- Header: Specifies the algorithm used to generate the signature.
- Payload: Contains the data (known as Claims) used for authentication, such as user grants, groups, or login timestamps.
- Signature: A cryptographic hash of the encoded header, encoded payload, and a secret/private key.
Unlike traditional token-based authorization where tokens are stored in a database, JWTs are validated by verifying the signature using a secret key known only to the server. The payload is encoded, not encrypted, meaning it can be read by anyone; however, it cannot be modified without invalidating the signature.
Implement the Context Cancellation Pipeline pattern in Go
The Context Cancellation pattern is used to forcibly terminate ongoing concurrent processes due to timeouts, errors, or other external factors. In Go, this is implemented using thecontext.ContextAPI, which carries deadlines, cancellation signals, and request-scoped values across API boundaries and goroutines.Prevent duplicate concurrent function calls with singleflight
Thesingleflightpackage is used to suppress duplicate function calls that occur simultaneously and produce the same output. This is particularly useful for expensive operations like generating reports or fetching data from a database where multiple users might request the same resource at the same time. Instead of executing the operation multiple times,singleflightensures the operation is performed only once, and all concurrent callers wait for and receive the same result.Understand Goroutine basics and resource usage
A Goroutine is a lightweight execution unit, often described as a 'mini thread'. They are asynchronous and significantly more efficient than native threads, requiring only about 2kB of memory to start. While Go can handle a vast number of goroutines, developers should consider the complexity of the logic within the goroutine, as it impacts hardware resource consumption beyond just the initial memory footprint.Understand LDAP and Directory Services basics
LDAP (Lightweight Directory Access Protocol) is a client-server protocol used to access Directory Services. Directory Services manage and provide access to network resources such as emails, computers, files, and printers. A key operation in LDAP is the 'Bind Operation', which is used to authenticate a client to the directory server and change the client's authorization state by sending a Bind DN and password.