### IDIN Core - Relational Database Get Started Source: https://idin-core.finema.dev/deeper/fcm Guide to getting started with relational databases in IDIN Core, including setup and basic operations. ```APIDOC Database (Relational) - Get Started: Purpose: Initial setup and configuration for relational database access. Connection: Details on establishing database connections. Basic Operations: Examples of performing CRUD operations. ``` -------------------------------- ### Hello, World! Example Source: https://idin-core.finema.dev/get-started A basic Go program demonstrating how to create and start an HTTP server using the idin-core framework. It sets up a root route that returns a 'Hello, World!' JSON response. ```go package main import ( "github.com/labstack/echo/v4" core "gitlab.finema.co/finema/idin-core" "net/http" ) func main() { // Create a new environment configuration env := core.NewEnv() // Create a new Echo HTTP server e := core.NewHTTPServer(&core.HTTPContextOptions{ ContextOptions: &core.ContextOptions{ ENV: env, }, }) // Define a route for the root path ("/") e.GET("", core.WithHTTPContext(func(c core.IHTTPContext) error { // Return a JSON response with a "message" field return c.JSON(http.StatusOK, core.Map{ "message": "Hello, World!", }) })) // Start the HTTP server core.StartHTTPServer(e, env) } ``` -------------------------------- ### Testing Get Started Source: https://idin-core.finema.dev/deeper/archiver Introduction to testing methodologies and setup within the IDIN Core framework. ```APIDOC Testing - Get Started: Purpose: Ensure the quality, reliability, and correctness of the application. Testing Types: - Unit Testing: Testing individual functions or methods in isolation. - Integration Testing: Testing the interaction between different components or services. - End-to-End (E2E) Testing: Testing the entire application flow from the user's perspective. Framework Integration: - The framework likely supports standard Go testing tools (`testing` package). - May integrate with testing frameworks like `testify/assert` for assertions. Directory Structure: - Test files typically reside in the same package as the code they test, with a `_test.go` suffix. - Example: `models/user_test.go` tests `models/user.go`. Running Tests: - Use the `go test` command: go test ./... go test ./models -v Key Principles: - Write tests before or alongside your code (TDD). - Aim for high test coverage. - Keep tests independent and repeatable. ``` -------------------------------- ### Install IDIN Core Source: https://idin-core.finema.dev/get-started Instructions for setting up IDIN Core, requiring Go v1.19 or higher. It demonstrates creating a new project directory and initializing a Go module. ```bash # Create a new directory and navigate into it mkdir myapp && cd myapp # Initialize a new Go module with the name "myapp" gomod init myapp ``` -------------------------------- ### IDIN Core Testing Get Started Source: https://idin-core.finema.dev/deploy/ci-cd This section provides an introduction to testing methodologies and setup within the IDIN Core framework. ```APIDOC Testing Get Started: Description: Introduces the testing framework and best practices for IDIN Core applications. Usage: - Write tests for different components (units, integrations, end-to-end). - Utilize the testing utilities provided. Key Concepts: - Test organization: Structuring test files and functions. - Test runners: Using `go test`. - Assertions: Employing assertion libraries. ``` -------------------------------- ### MongoDB Get Started Source: https://idin-core.finema.dev/deeper/archiver Guide to setting up and connecting to MongoDB databases within the IDIN Core framework. ```APIDOC Database (MongoDB) - Get Started: Purpose: Connect to and interact with MongoDB databases. Configuration: - MongoDB connection details are typically configured via environment variables or a config file. - Key parameters include: - MONGO_URI (string): The MongoDB connection string (e.g., "mongodb://user:password@host:port/database?options"). Connection: - The framework likely uses a MongoDB driver (e.g., `mongo-driver`). - Example function signature: ConnectMongo(uri string) (*mongo.Client, error) Usage: - Once connected, you can access databases and collections. - Perform CRUD (Create, Read, Update, Delete) operations using the driver's methods. - Example: `collection := client.Database("mydb").Collection("mycollection")` ``` -------------------------------- ### IDIN Core - Testing Get Started Source: https://idin-core.finema.dev/deeper/fcm Introduction to testing strategies and setup within the IDIN Core framework. ```APIDOC Testing - Get Started: Purpose: Overview of testing approaches in IDIN Core. Setup: Initial configuration for the testing environment. Best Practices: Recommendations for effective testing. ``` -------------------------------- ### IDIN Core Deployment - Get Started Source: https://idin-core.finema.dev/deeper/queues Getting started with deploying IDIN Core applications. ```APIDOC Deployment - Get Started: Overview: Deployment strategies for IDIN Core applications. Prerequisites: Environment setup for deployment. Build Process: Steps to build the application for deployment. ``` -------------------------------- ### MongoDB Get Started Source: https://idin-core.finema.dev/deploy/kubernetes Introduction to using MongoDB with IDIN Core. Covers setup, connection, and basic document operations. ```APIDOC Database (MongoDB) Get Started: Get Started: https://idin-core.finema.dev/mongodb/get-started.html Description: Initial setup and connection to MongoDB. Key Features: - MongoDB connection string - Database and collection selection - Basic document insertion and retrieval ``` -------------------------------- ### IDIN Core Testing - Get Started Source: https://idin-core.finema.dev/deeper/queues Getting started with testing in IDIN Core. ```APIDOC Testing - Get Started: Frameworks: Overview of testing frameworks used. Setup: Configuring the testing environment. Writing Tests: Basic structure of a test case. ``` -------------------------------- ### Relational Database Get Started Source: https://idin-core.finema.dev/deeper/archiver Guide to setting up and connecting to relational databases within the IDIN Core framework. ```APIDOC Database (Relational) - Get Started: Purpose: Connect to and interact with relational databases (e.g., PostgreSQL, MySQL). Configuration: - Database connection details are typically configured via environment variables or a config file. - Key parameters include: - DB_DRIVER (string): The database driver (e.g., 'postgres', 'mysql'). - DB_HOST (string): The database host address. - DB_PORT (int): The database port. - DB_USER (string): The database username. - DB_PASSWORD (string): The database password. - DB_NAME (string): The database name. Connection: - The framework likely provides a function or service to establish a database connection. - Example function signature: Connect(driver, dsn string) (*sql.DB, error) Usage: - Once connected, you can execute SQL queries using the standard database/sql package. - The framework may offer an ORM or query builder for more convenient database interactions. ``` -------------------------------- ### IDIN Core Database (MongoDB) - Get Started Source: https://idin-core.finema.dev/deeper/queues Getting started guide for using MongoDB with IDIN Core. ```APIDOC Database (MongoDB) - Get Started: Setup: Connecting to MongoDB instances. Configuration: MongoDB connection URI and options. Basic Operations: Performing CRUD operations on collections. ``` -------------------------------- ### Relational Database Get Started Source: https://idin-core.finema.dev/deploy/kubernetes Introduction to using relational databases with IDIN Core. Covers setup, connection, and basic operations. ```APIDOC Database (Relational) Get Started: Get Started: https://idin-core.finema.dev/database/get-started.html Description: Initial setup and connection to relational databases. Key Features: - Database driver configuration - Connection pooling - Basic query execution ``` -------------------------------- ### Hello World Example in Go Source: https://idin-core.finema.dev/th/get-started A basic Go program demonstrating how to initialize the IDIN Core environment, set up an Echo HTTP server, define a root route that returns 'สวัสดีชาวโลก!', and start the server. ```go package main import ( "github.com/labstack/echo/v4" core "gitlab.finema.co/finema/idin-core" "net/http" ) func main() { // Create a new environment configuration env := core.NewEnv() // Create a new Echo HTTP server e := core.NewHTTPServer(&core.HTTPContextOptions{ ContextOptions: &core.ContextOptions{ ENV: env, }, }) // Define the route for the root path ("/") e.GET("", core.WithHTTPContext(func(c core.IHTTPContext) error { // Return JSON data with a "message" field return c.JSON(http.StatusOK, core.Map{ "message": "สวัสดีชาวโลก!", }) })) // Start the HTTP server core.StartHTTPServer(e, env) } ``` -------------------------------- ### IDIN Core MongoDB Get Started Source: https://idin-core.finema.dev/deploy/ci-cd This section provides guidance on setting up and connecting to MongoDB databases within the IDIN Core framework. ```APIDOC Database (MongoDB) Get Started: Description: Guides users through connecting to and interacting with MongoDB. Usage: - Configure MongoDB connection URI. - Initialize the MongoDB client session. Key Operations: - Connect to MongoDB: `mongo.Connect(ctx, clientOptions)` - Ping MongoDB: `client.Ping(ctx, nil)` Dependencies: - MongoDB server instance. - MongoDB driver for Go (`go.mongodb.org/mongo-driver`). ``` -------------------------------- ### IDIN Core - MongoDB Get Started Source: https://idin-core.finema.dev/deeper/fcm Introduction to using MongoDB with IDIN Core, covering setup and basic operations. ```APIDOC Database (MongoDB) - Get Started: Purpose: Initial setup for MongoDB integration. Connection: Details on connecting to a MongoDB instance. Basic Operations: Examples of performing CRUD operations with MongoDB. ``` -------------------------------- ### Configure Private Repository Access Source: https://idin-core.finema.dev/get-started Sets up the necessary environment variables and Git configurations to access private Go modules from gitlab.finema.co. ```bash export GOPRIVATE=gitlab.finema.co/finema/* git config --global url."git@gitlab.finema.co:".insteadOf "https://gitlab.finema.co/" g o get gitlab.finema.co/finema/idin-core ``` -------------------------------- ### IDIN Core Database (Relational) - Get Started Source: https://idin-core.finema.dev/deeper/queues Getting started guide for using relational databases with IDIN Core. ```APIDOC Database (Relational) - Get Started: Setup: Connecting to relational databases (e.g., PostgreSQL, MySQL). Configuration: Database connection string and driver setup. Basic Operations: Performing CRUD operations. ``` -------------------------------- ### Main Application Setup Source: https://idin-core.finema.dev/basics/routing Provides the Go code for setting up the main application, including initializing the environment, creating the HTTP server, and starting the server. ```go package main import( "github.com/labstack/echo/v4" core "gitlab.finema.co/finema/idin-core" "net/http" ) func main(){ // Create a new environment configuration env := core.NewEnv() // Create a new HTTP server e := core.NewHTTPServer(&core.HTTPContextOptions{ ContextOptions:&core.ContextOptions{ ENV: env, }, }) // Define NewUserHTTP user.NewUserHTTP(e) // Start the HTTP server core.StartHTTPServer(e, env) } ``` -------------------------------- ### IDIN Core Relational Database Get Started Source: https://idin-core.finema.dev/deploy/ci-cd This section provides guidance on setting up and connecting to relational databases within the IDIN Core framework. ```APIDOC Database (Relational) Get Started: Description: Guides users through connecting to and interacting with relational databases. Usage: - Configure database connection string (driver, host, port, user, password, dbname). - Initialize the database connection pool. Key Operations: - Connect to DB: `sql.Open(driverName, dataSourceName)` - Ping DB: `db.Ping()` Dependencies: - SQL database driver (e.g., `github.com/lib/pq` for PostgreSQL, `github.com/go-sql-driver/mysql` for MySQL). - Go's `database/sql` package. ``` -------------------------------- ### Run the Application Source: https://idin-core.finema.dev/get-started Command to compile and run the Go application from the main.go file. ```bash $ go run main.go ``` -------------------------------- ### IDIN Core General Guide Source: https://idin-core.finema.dev/testing/unit-testing This section provides general guidance and concepts for the IDIN Core framework, including getting started, architecture, and conventional commits. ```markdown [Get Started ](https://idin-core.finema.dev/get-started.html) [Architecture Concepts ](https://idin-core.finema.dev/architecture.html) [Conventional Commits ](https://idin-core.finema.dev/commits.html) ``` -------------------------------- ### Install Testify Source: https://idin-core.finema.dev/testing/get-started Command to install the Testify testing toolkit for Golang using go get. ```bash gogetgithub.com/stretchr/testify ``` -------------------------------- ### IDIN Core Database (MongoDB): Get Started Source: https://idin-core.finema.dev/basics/env This section provides an introduction to using MongoDB with IDIN Core. It covers initial setup, connection configuration, and basic MongoDB operations. ```APIDOC Database (MongoDB) - Get Started: - Guides on connecting to and interacting with MongoDB. - Covers MongoDB connection string configuration. - Introduces basic CRUD operations for MongoDB documents. - Example Configuration: `mongo.Connect("mongodb://user:pass@host:port/dbname")` ``` -------------------------------- ### Install IDIN Core Source: https://idin-core.finema.dev/th/get-started Steps to install the IDIN Core Go package, including initializing a Go module, setting private repository configurations, and fetching the package. ```bash mkdir myapp && cd myapp gomod init myapp export GOPRIVATE=gitlab.finema.co/finema/* git config --global url."git@gitlab.finema.co:".insteadOf "https://gitlab.finema.co/" goget gitlab.finema.co/finema/idin-core ``` -------------------------------- ### IDIN Core Testing: Get Started Source: https://idin-core.finema.dev/basics/env This section provides an introduction to testing methodologies within IDIN Core. It covers setting up the testing environment and writing basic tests. ```APIDOC Testing - Get Started: - Introduces the testing framework and practices in IDIN Core. - Covers setting up test environments and dependencies. - Explains how to write and run basic test cases. - Example Test Structure: `func TestMyFunction(t *testing.T) { // Arrange // Act // Assert }` ``` -------------------------------- ### IDIN Core Database (Relational): Get Started Source: https://idin-core.finema.dev/basics/env This section provides an introduction to using relational databases with IDIN Core. It covers initial setup, connection configuration, and basic database operations. ```APIDOC Database (Relational) - Get Started: - Guides on connecting to and interacting with relational databases (e.g., PostgreSQL, MySQL). - Covers database driver configuration and connection pooling. - Introduces basic CRUD (Create, Read, Update, Delete) operations. - Example Configuration: `db.Connect("postgres://user:pass@host:port/dbname")` ``` -------------------------------- ### Dockerfile for Go Application Source: https://idin-core.finema.dev/deploy/get-started This Dockerfile sets up a multi-stage build process for a Go application. It first builds the application in a Go environment and then copies the executable to a minimal Alpine Linux image for the production environment. ```dockerfile FROM golang:1.19 AS builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -o main . FROM alpine:3.16 WORKDIR /root/ COPY --from=builder /app/main . CMD ["./main"] ``` -------------------------------- ### IDIN Core HTTP Client Usage Example Source: https://idin-core.finema.dev/deeper/http-client Provides a practical example of how to use the IDIN Core HTTP client to make a GET request. This demonstrates the instantiation of the client and the application of request options. ```go client := NewHTTPClient() resp, err := client.Get("https://api.example.com/data", WithHeaders(map[string]string{ "Authorization": "Bearer YOUR_TOKEN", }), WithQuery(map[string]string{ "param1": "value1", })) if err != nil { // Handle error } // Process response.Body, response.StatusCode, etc. ``` -------------------------------- ### Environment Configuration Source: https://idin-core.finema.dev/get-started Defines the environment variables for the application, including host, environment type, and log level. ```env HOST=0.0.0.0:3000 ENV=dev LOG_LEVEL=debug ``` -------------------------------- ### Install Testify Source: https://idin-core.finema.dev/testing/unit-testing Installs the stretchr/testify testing framework for Go projects using the go get command. ```shell go get github.com/stretchr/testify ``` -------------------------------- ### Dockerfile for IDIN Core Deployment Source: https://idin-core.finema.dev/deploy/get-started This Dockerfile is used to build a GoLang application deployment for IDIN Core. It specifies the base image, copies Go module files, and downloads dependencies. ```dockerfile FROM registry.finema.co/finema/idin-core:1.4.2 # Copy Go module files to the build environment ADD go.mod go.sum /app/ # Download Go module dependencies RUN go mod download ``` -------------------------------- ### Makefile Commands for Testing and Installation Source: https://idin-core.finema.dev/basics/makefile This snippet demonstrates common Makefile targets for running tests (unit, integration, and end-to-end) and installing dependencies using Go. ```makefile test: go test ./... test-e2e: go test --tags=e2e ./... test-integration: go test --tags=integration ./... install: go get ``` -------------------------------- ### Build Docker Image Source: https://idin-core.finema.dev/deploy/get-started Command to build the Docker image for the Go application. The '-t' flag tags the image with a name. ```shell docker build -t my-go-app . ``` -------------------------------- ### Environment Variables (.env file) Source: https://idin-core.finema.dev/deploy/get-started This file defines environment variables for the Go application, specifying the host and port, the environment type, and the logging level. ```plaintext HOST=0.0.0.0:3000 ENV=dev LOG_LEVEL=debug ``` -------------------------------- ### Golang Service Example Source: https://idin-core.finema.dev/basics/service Demonstrates the creation of a service in Golang within the IDIN Core framework. This example focuses on authentication-related functionalities. ```go package main import ( "fmt" "github.com/gin-gonic/gin" ) // AuthService defines the service for authentication. type AuthService struct { // Dependencies can be injected here } // NewAuthService creates a new instance of AuthService. func NewAuthService() *AuthService { return &AuthService{} } // Login handles the user login process. func (s *AuthService) Login(c *gin.Context) { // Implementation for login fmt.Println("Login endpoint hit") c.JSON(200, gin.H{ "message": "Login successful" }) } // Register handles the user registration process. func (s *AuthService) Register(c *gin.Context) { // Implementation for registration fmt.Println("Register endpoint hit") c.JSON(200, gin.H{ "message": "Registration successful" }) } func main() { router := gin.Default() authService := NewAuthService() // Define routes for authentication service authGroup := router.Group("/auth") authGroup.POST("/login", authService.Login) authGroup.POST("/register", authService.Register) router.Run(":8080") } ``` -------------------------------- ### IDIN Core Database (Relational) Guide Source: https://idin-core.finema.dev/testing/unit-testing This section details the relational database functionalities within the IDIN Core framework, including setup, pagination, repositories, migrations, and seeding. ```markdown [Get Started ](https://idin-core.finema.dev/database/get-started.html) [Pagination ](https://idin-core.finema.dev/database/pagination.html) [Repository ](https://idin-core.finema.dev/database/repository.html) [Migrations ](https://idin-core.finema.dev/database/migrations.html) [Seeding ](https://idin-core.finema.dev/database/seeding.html) ``` -------------------------------- ### StartHTTPServer Function Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Starts the HTTP server instance provided by echo.Echo, utilizing the IENV interface for environment configuration. ```go func StartHTTPServer(e *echo.Echo, env IENV) ``` -------------------------------- ### IDIN Core Database (MongoDB) Guide Source: https://idin-core.finema.dev/testing/unit-testing This section details the MongoDB functionalities within the IDIN Core framework, including setup, pagination, repositories, migrations, and seeding. ```markdown [Get Started ](https://idin-core.finema.dev/mongodb/get-started.html) [Pagination ](https://idin-core.finema.dev/mongodb/pagination.html) [Repository ](https://idin-core.finema.dev/mongodb/repository.html) [Migrations ](https://idin-core.finema.dev/mongodb/migrations.html) [Seeding ](https://idin-core.finema.dev/mongodb/seeding.html) ``` -------------------------------- ### IDIN Core Basics: Makefile Source: https://idin-core.finema.dev/th/commits Provides examples and explanations for using Makefiles to automate tasks in IDIN Core projects. ```makefile # Makefile example for IDIN Core APP_NAME=idin-core-app build: go build -o $(APP_NAME) . run: ./$(APP_NAME) clean: rm -f $(APP_NAME) .PHONY: build run clean ``` -------------------------------- ### Install Dependencies Source: https://idin-core.finema.dev/basics/makefile Installs project dependencies using the 'goget' command. ```shell goget ``` -------------------------------- ### Mocking a Database Get Method Source: https://idin-core.finema.dev/testing/get-started Demonstrates how to create a mock database object and define the behavior of its `Get` method using Testify's mocking capabilities. ```go db := mock.NewMockDatabase() db.On("Get","1").Return(10) ``` -------------------------------- ### Environment Configuration Source: https://idin-core.finema.dev/th/get-started Example .env file for configuring the IDIN Core application, specifying host, environment, and log level. ```env HOST=0.0.0.0:3000 ENV=dev LOG_LEVEL=debug ``` -------------------------------- ### Create and Run Database Instance with Go Source: https://idin-core.finema.dev/database/get-started This Go code snippet demonstrates how to create a new environment configuration, connect to the MySQL database using the provided configuration, and start an HTTP server. It includes error handling for the database connection. ```go // APIRun is the main function to start the application. func APIRun(){ // Create a new environment configuration env := core.NewEnv() // Connect to Database db, err := core.NewDatabase(env.Config()).Connect() if err !=nil{ fmt.Fprintf(os.Stderr,"MySQL: %v", err) os.Exit(1) } fmt.Println("Database connected successfully!") // Create a new HTTP server e := core.NewHTTPServer(&core.HTTPContextOptions{ ContextOptions:&core.ContextOptions{ DB: db, ENV: env, }, }) // Start the HTTP server core.StartHTTPServer(e, env) } ``` -------------------------------- ### Run the Application Source: https://idin-core.finema.dev/database/get-started Command to execute the Go application after setting up the environment and code. ```bash $ gorun main.go ``` -------------------------------- ### Go Package Overview and Index Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Provides access to the Go package documentation, including overview, index, and subdirectories. Links to the local Go documentation server are also provided. ```go import "gitlab.finema.co/finema/idin-core" // Overview: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index.html#pkg-overview // Index: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index.html#pkg-index // Subdirectories: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index.html#pkg-subdirectories // GoDoc Server: http://localhost:6060/pkg/ ``` -------------------------------- ### Go HTTP GET Request Example Source: https://idin-core.finema.dev/deeper/http-client Demonstrates making a GET request with custom options including base URL, timeout, headers, parameters, and retry count. Handles response and errors. ```go import ( "fmt" "time" xurl "net/url" "net/http" ) func(s someService)SomeFunc(){ // Get the requester from the context requester := s.ctx.Requester() // Create the options for the request options :=&RequesterOptions{ BaseURL:"https://api.example.com", Timeout: time.Second *10, Headers: http.Header{ "Authorization":[]string{"Bearer token123"}, }, Params: xurl.Values{ "param1":[]string{"value1"}, "param2":[]string{"value2"}, }, RetryCount:3, IsMultipartForm:false, IsURLEncode:true, IsBodyRawByte:false, } // Make a GET request using the requester and options response, err := requester.Get("/users", options) if err !=nil{ fmt.Println("Error:", err) return } // Print the response status code, data, and raw data fmt.Println("Response Status Code:", response.StatusCode) fmt.Println("Response Data:", response.Data) fmt.Println("Response Raw Data:",string(response.RawData)) } ``` -------------------------------- ### Run the Server Source: https://idin-core.finema.dev/th/get-started Command to run the Go application after setting up the project and code. ```bash $gorunmain.go ``` -------------------------------- ### Example: Getting a Value by Key Source: https://idin-core.finema.dev/deeper/redis Demonstrates retrieving a string value associated with a key from the cache and printing it. ```go var value string err := ctx.Cache().Get(&value,"mykey") if err != nil{ // handle error } fmt.Println(value) ``` -------------------------------- ### Send Query Parameters with Curl Source: https://idin-core.finema.dev/basics/request Example of sending query parameters with a GET request using `curl`. Parameters are appended to the URL after a '?'. ```bash curl \ -X GET \ http://localhost:3000?name=Joe ``` -------------------------------- ### Create and Configure Echo Server with Middleware Source: https://idin-core.finema.dev/basics/middleware Demonstrates the creation of a new environment configuration and an Echo HTTP server, followed by registering a basic GET route with placeholder handlers and middleware. ```go env := core.NewEnv() e.GET("/",,) ``` -------------------------------- ### Testing Mocked Method Return Value Source: https://idin-core.finema.dev/testing/get-started An example of a Golang test function that uses a mocked database object and asserts that the `Get` method returns the expected value. ```go funcTestGet(t *testing.T){ db := mock.NewMockDatabase() db.On("Get","1").Return(10) actual := db.Get("1") assert.Equal(t,10, actual) } ``` -------------------------------- ### Get JSON Value from Cache Source: https://idin-core.finema.dev/deeper/redis Illustrates how to retrieve a JSON value from the cache and unmarshal it into a Go struct. It shows the method signature for GetJSON and provides an example of its usage. ```go func(c cache)GetJSON(dest interface{}, key string)error ``` ```go var data struct{ Name string`json:"name"` } err := ctx.Cache().GetJSON(&data,"myjson") if err !=nil{ // handle error } fmt.Println(data.Name) ``` -------------------------------- ### Database Constructors and Connect Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Functions for creating and connecting to a database. Supports creating a database instance with environment configuration and optionally with custom GORM configuration. ```go func NewDatabase(env *ENVConfig) *Database func NewDatabaseWithConfig(env *ENVConfig, config *gorm.Config) *Database func (db *Database) Connect() (*gorm.DB, error) ``` -------------------------------- ### Application Entry Point and Server Initialization Source: https://idin-core.finema.dev/architecture Describes the application's entry point via the `main` function in the `main` package, which triggers `APIRun` to initialize the environment, connect to the database, and construct the HTTP server. ```go main.main(): Calls cmd.APIRun() cmd.APIRun(): Initializes application environment. Connects to the database. Constructs HTTP server using core.NewHTTPServer(ctxOptions...). ``` -------------------------------- ### IDIN Core Database (Relational) Guide Source: https://idin-core.finema.dev/testing/end-to-end-testing This section details the usage of relational databases within the IDIN Core framework. It covers setup, pagination, repository patterns, migrations, and seeding. ```APIDOC Database (Relational): Get Started: Instructions for connecting to and configuring relational databases. Pagination: Implementing pagination for database queries. Repository: Using the repository pattern for data access. Migrations: Managing database schema changes with migrations. Seeding: Populating the database with initial data. ``` -------------------------------- ### IDIN Core Database (MongoDB) Guide Source: https://idin-core.finema.dev/testing/end-to-end-testing This section details the usage of MongoDB databases within the IDIN Core framework. It covers setup, pagination, repository patterns, migrations, and seeding. ```APIDOC Database (MongoDB): Get Started: Instructions for connecting to and configuring MongoDB. Pagination: Implementing pagination for MongoDB queries. Repository: Using the repository pattern for data access. Migrations: Managing database schema changes. Seeding: Populating the database with initial data. ``` -------------------------------- ### IDIN Core Basics: Environment Variables Source: https://idin-core.finema.dev/th/get-started Explains how to manage application configuration using environment variables, typically loaded from a .env file. ```Go package main import ( "fmt" "github.com/gin-gonic/gin" "github.com/joho/godotenv" "os" ) func main() { // Load .env file err := godotenv.Load() if err != nil { log.Fatal("Error loading .env file") } port := os.Getenv("APP_PORT") if port == "" { port = "8080" // Default port } router := gin.Default() router.GET("/config", func(c *gin.Context) { apiKey := os.Getenv("API_KEY") c.JSON(200, gin.H{ "message": "Configuration loaded", "app_port": port, "api_key_set": apiKey != "", }) }) router.Run(":" + port) } ``` -------------------------------- ### NewDatabase Constructor Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Function to create a new Database instance, requiring an ENVConfig for configuration. ```go func NewDatabase(env *ENVConfig) *Database ``` -------------------------------- ### Run Docker Container Source: https://idin-core.finema.dev/deploy/get-started Command to run a Docker container from the built image. It specifies detached mode, a container name, port mapping, and loads environment variables from a .env file. ```shell docker run -d --name my-go-container -p 3000:3000 --env-file .env my-go-app ``` -------------------------------- ### Golang Testify E2E Test Suite Setup Source: https://idin-core.finema.dev/testing/end-to-end-testing Demonstrates setting up a test suite for E2E testing in Golang using the Testify framework. It includes the basic structure for a test suite and the entry point for running it. ```go package services import( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" core "gitlab.finema.co/finema/idin-core" ) type UserServiceSuitestruct{ suite.Suite ctx core.IE2EContext } funcTestUserServiceSuite(t *testing.T){ suite.Run(t,new(UserServiceSuite)) } ``` -------------------------------- ### Conventional Commits Examples Source: https://idin-core.finema.dev/th/commits Provides practical examples of commit messages adhering to the Conventional Commits specification. These examples illustrate the correct usage of types, scopes, and messages. ```APIDOC Commit Message Examples: - feat(auth): Add login functionality - fix(api): Resolve issue with search endpoint - docs(readme): Update installation instructions ``` -------------------------------- ### IDIN Core Deployment - Gitlab CI/CD Source: https://idin-core.finema.dev/deeper/queues Documentation on setting up CI/CD pipelines for IDIN Core applications using GitLab CI/CD. ```APIDOC Deployment - Gitlab CI/CD: .gitlab-ci.yml: Configuring CI/CD pipelines. Stages: Defining pipeline stages (build, test, deploy). CI Variables: Using CI/CD variables for configuration. Deployment Jobs: Automating deployment to various environments. ``` -------------------------------- ### Route Registration Examples Source: https://idin-core.finema.dev/basics/routing Demonstrates how to register different types of routes, including static paths, paths with parameters, and paths with wildcards, using the Echo framework. ```go // Routes e.GET("/user/john", core.WithHTTPContext(func(c core.IHTTPContext)error{ return c.JSON(http.StatusOK,"/user/john") })) e.GET("/user/:id", core.WithHTTPContext(func(c core.IHTTPContext)error{ return c.JSON(http.StatusOK,"/user/:id") })) e.GET("/user/john/*", core.WithHTTPContext(func(c core.IHTTPContext)error{ return c.JSON(http.StatusOK,"/user/john/*") })) ``` -------------------------------- ### Conventional Commits Examples Source: https://idin-core.finema.dev/commits Provides examples of conventional commit messages illustrating different types (feat, fix, docs, style, refactor, test, chore) and scopes. These examples demonstrate how to structure commit messages effectively. ```APIDOC Examples: feat(auth): implement JWT authentication fix(api): correct user endpoint response docs(readme): update installation instructions style(ui): format code according to linting rules refactor(core): simplify data processing logic test(service): add unit tests for payment gateway chore(deps): update dependencies to latest versions ``` -------------------------------- ### Install Knex.js and TypeScript Source: https://idin-core.finema.dev/database/migrations Installs Knex.js and TypeScript as development dependencies for a Node.js project. ```shell npminit-y npminstallknex npminstall--save-devknex npminstall--save-devtypescript ``` -------------------------------- ### DatabaseMongo Constructor and Connect Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Enables the creation and connection to a MongoDB instance. Initializes a DatabaseMongo with environment configuration and establishes a connection. ```go func NewDatabaseMongo(env *ENVConfig) *DatabaseMongo func (db *DatabaseMongo) Connect() (IMongoDB, error) ``` -------------------------------- ### MQContext Start Method Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Starts the message queue context, likely initiating background processes for message handling. ```go func (c *MQContext) Start() ``` -------------------------------- ### Conventional Commit Examples Source: https://idin-core.finema.dev/commits Provides practical examples of how to write conventional commit messages for different scenarios, illustrating the use of types and scopes. ```markdown feat(auth): Add login functionality fix(api): Handle edge case in search endpoint docs(readme): Update installation instructions ``` -------------------------------- ### Kubernetes Deployment Steps Source: https://idin-core.finema.dev/deploy/kubernetes This section outlines the steps to deploy a GoLang application on Kubernetes, including creating deployment, ConfigMap, Service, and Ingress configurations. ```APIDOC Kubernetes Deployment Steps: 1. Create Deployment Configuration (`deployment.yaml`): - Defines the application's desired state, including image, replicas, and update strategy. - Example: `apiVersion: apps/v1`, `kind: Deployment`, `metadata`, `spec`. 2. Create ConfigMap: - Stores configuration data as key-value pairs. - Used to inject environment variables or configuration files into pods. 3. Create Service: - Exposes the application running on a set of Pods as a network service. - Defines how to access the application within the cluster. 4. Create Ingress: - Manages external access to the services in a cluster, typically HTTP. - Provides routing, SSL termination, and load balancing. 5. Deploy the Application: - Apply the created YAML files to the Kubernetes cluster using `kubectl apply -f `. 6. Access the Deployed Application: - Use the Ingress rules or Service's NodePort/LoadBalancer IP to access the application. ``` -------------------------------- ### Environment Configuration in Go Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Manages application configuration loaded from environment variables. Includes mock implementations for testing. ```go package idin_core // EnvManager handles environment variable loading and access. type EnvManager interface { Get(key string) string GetInt(key string) (int, error) GetBool(key string) (bool, error) } // EnvManagerMock provides a mock implementation of EnvManager. type EnvManagerMock interface { // Mock methods } ``` -------------------------------- ### NewWinRM Function Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Creates a new WinRM client. It requires a context as input. ```go func NewWinRM(ctx IContext) IWinRM ``` -------------------------------- ### Integration Test Example: TestCreate Source: https://idin-core.finema.dev/testing/integration-testing An example of a single integration test case for creating a user within the UserService. This snippet focuses on the assertion logic using Testify. ```go func (s *UserServiceSuite) TestCreate() { user := &User{ Name: "John Doe", Email: "john.doe@example.com", } createdUser, err := userService.CreateUser(user) sassert.NoError(s.T(), err) assert.NotNil(s.T(), createdUser) assert.Equal(s.T(), user.Name, createdUser.Name) assert.Equal(s.T(), user.Email, createdUser.Email) } ``` -------------------------------- ### Example HTTP 400 Response (JSON) Source: https://idin-core.finema.dev/basics/validation An example JSON structure for an HTTP 400 Bad Request response, indicating invalid parameters with specific field errors. ```json { "code":"INVALID_PARAMS", "message":"Invalid parameters", "fields":{ "password":{ "code":"REQUIRED", "message":"The password field is required" }, "username":{ "code":"REQUIRED", "message":"The username field is required" } } } ``` -------------------------------- ### IDIN Core Basics: Makefile Usage Source: https://idin-core.finema.dev/th/get-started Illustrates common tasks automated using a Makefile, such as building, running, testing, and deploying the application. ```Makefile # Makefile example for IDIN Core project APP_NAME=idin-core .PHONY: all build run test clean all: build build: @echo "Building $(APP_NAME)..." @go build -o $(APP_NAME) . run: @echo "Running $(APP_NAME)..." @./$(APP_NAME) # Example for running with specific environment variables run-dev: @echo "Running $(APP_NAME) in development mode..." @APP_ENV=development PORT=3000 ./$(APP_NAME) # Assuming you have tests defined in your Go code test: @echo "Running tests..." @go test ./... clean: @echo "Cleaning build artifacts..." @rm -f $(APP_NAME) ``` -------------------------------- ### Logger Initialization and Usage Source: https://idin-core.finema.dev/godoc/pkg/gitlab.finema.co/finema/idin-core/index Details the creation of Logger instances, both with and without a context, and provides methods for logging debug messages. This covers the basic logging capabilities of the system. ```go func NewLogger(ctx IContext) *Logger func NewLoggerSimple() *Logger func (logger *Logger) Debug(args ...interface{}) func (logger *Logger) DebugWithSkip ```