$ # Go 1.16+
$ go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@$TAG
migration in sqlc
sqlc does not perform database migrations for you. However, sqlc is able to differentiate between up and down migrations. sqlc ignores down migrations when parsing SQL files.
sqlc supports parsing migrations from the following tools:
dbmate
golang-migrate
goose
sql-migrate
tern
comparing database/sql package, gorm, sqlx, and sqlc
A transaction is a single logical unit of work that accesses and possibly modifies the contents of a database. Transactions access data using read and write operations.
In order to maintain consistency in a database, before and after the transaction, certain properties are followed. These are called ACID properties.
In a database, a deadlock is a situation in which two or more transactions are waiting for one another to give up locks. For example, Transaction A might hold a lock on some rows in the Accounts table and needs to update some rows in the Orders table to finish.
Mock testing are using "White Box" testing techniques, used to testing every functional func in code. (https://github.com/golang/mock)
Stub is replacement for some dependency in your code that will be used during test execution. It is typically built for one particular test and unlikely can be reused for another because it has hardcoded expectations and assumptions.
Testing Method TDD / BDD / ATDD
TDD (test-driven development) approach with step:
First creating failing unit test.
Then start implementing unit test with MINIMAL code until all unit test condition are satisfied.
Last testing are passed, programmer refactor the design & making an improvement without changing the behavior from second step.
TDD in short explanation:
TDD steps :
Create unit test(Code) that including all process nedeed/writen.
Test unitTest (Failed result test).
Then repeating changes/implement code until all test are passed.
Done TDD cycle.
TDD Auidence are programmer-side since it's focuses more on code implementation of a feature.
TDD are more likely realted to "White Box" testing techniques.
BDD (Behavioral-Driven Development) are derived/similar from TDD but using the Given-When-Then approach is used for writing test cases. Some Given-When-Then example:
Given the user has entered valid login credentials
When a user clicks on the login button
Then display the successful validation message
BDD in short explanation:
BDD Steps are similar to TDD but "unit test" test are changed to Behavioral test that writen and describe in human language (ex:English).
BDD Auidence are more wide to other than programmer team, because main focus on Understanding Requirements.
BDD are more likely realted to "Black Box" testing techniques.
ATDD (Acceptance Test-Driven development) are similar with BDD focuses more on the behavior of the feature, whereas ATDD focuses on capturing the precise requirements.
ATDD in short explanation:
BDD are still very similar to BDD testing techniques but focusing in More detailed an precise requirements at development feature.
create a new docker network and listed images to network
Create docker serveral docker images with docker-compose.yaml
With docker-compose.yaml we can automated creating serveral docker images and listed it to same network automaticly
Section Session & GRPC
Session token and Access Token
Refresh tokens provide a way to bypass the temporary nature of access tokens. Normally, a user with an access token can only access protected resources or perform specific actions for a set period of time, which reduces the risk of the token being compromised. A refresh token allows the user to get a new access token without needing to log in again.
Some option we can use for protoc generation write inside protobuffer services. >>>>> Do not Forget to copy .proto file to project path as import depedency
To use Service definition using server reflection, gRPC server mus registeret to pakcage reflection
reflection.Register(grpcServer)
gRPC gateway
gRPC-Gateway is a plugin of protoc. It reads a gRPC service definition and generates a reverse-proxy server which translates a RESTful JSON API into gRPC.
This project aims to provide that HTTP+JSON interface to your gRPC service because, you might still want to provide a traditional RESTful JSON API as well. Reasons can range from maintaining backward-compatibility, supporting languages or clients that are not well supported by gRPC
in gin using binding/v10 in gRPC using "google.golang.org/genproto/googleapis/rpc/errdetails"
when making error validtaion best practice to write field same as request param name (ex : full_name) to create consistency.
Authentication in GRPC
SSL/TLS: gRPC has SSL/TLS integration and promotes the use of SSL/TLS to authenticate the server.
ALTS: gRPC supports ALTS as a transport security mechanism.
Token-based authentication with Google : gRPC provides a generic mechanism to attach metadata based credentials to requests and responses.
Google credentials should only be used to connect to Google services. Sending a Google issued OAuth2 token to a non-Google service could result in this token being stolen and used to impersonate the client to Google services.
Swagger UI allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy for back end implementation and client side consumption.
using it in our local server with just adding swagger-ui/dist to our project and serve it as fileserver
using rakyll/statik to allows you to embed a directory of static files into your Go binary (it' wil faster since it's no need to read file when called)
standart liblary from go :https://pkg.go.dev/net/smtp (The smtp package is frozen and is not accepting new features. Some external packages provide more functionality.)
PUT modifies a record's information and creates a new record if one is not available, and PATCH updates a resource without sending the entire body in the request.
Postman for testing Support http, gRPC, documenting, easy value set, etc