Spring Master Slave Databas Configuration and Dynamic Datasource Switching Principles

In large applications, it is a common design pattern to configure master-slave databases and use read-write separation. In Spring applications, to implement read-write separation, it is best to not make changes to existing code, but to support it transparently at the bottom. Spring has a built-in AbstractRoutingDataSource that can configure multiple data sources into a Map and then, depending on the key, return different data sources. Because AbstractRoutingDataSource is also a DataSource interface, the application can set the key first, and the code that accesses the database can get the corresponding real data source from AbstractRoutingDataSource to access the specified database.

Real Time Hot Reloading of Go Programs Using Air

Today we want to introduce a magic tool - Air can listen to the project’s code files in real time, and automatically recompile and execute the code after changes, greatly improving the development efficiency of gin framework projects. Why do I need real-time loading When using Python to write Web projects, the common Flask or Django frameworks support live-loading, and after you modify the project code, the program can automatically reload and execute (live-reload), which is very convenient in the daily development phase.

React Code Sharing Best Practices Approach

When any project grows to a certain complexity, it is bound to face the problem of logic reuse. In React, there are several ways to implement logic reuse: Mixin, HOC, Decorator, Render Props, Hook, etc. This article mainly analyzes the advantages and disadvantages of these ways to help developers make a more suitable way for business scenarios. Mixin Mixin has been widely used in various object-oriented languages to create a

Fasttemplate Simple Tutorial

fasttemplate is a relatively simple and easy to use small template library . The author of fasttemplate, valyala, has additionally open sourced a number of excellent libraries, such as the famous fasthttp. fasttemlate only focuses on a very small area - string replacement. Its goal is to replace strings.Replace, fmt.Sprintf and other methods to provide a simple, easy-to-use, high-performance string replacement method. Quick Use Create the directory and initialize. 1 2 $ mkdir fasttemplate && cd fasttemplate $ go mod init github.

Analysis of the Problems Caused by Replacing Fastjson With Gson

The security vulnerability of Json serialization framework has always been a topic of conversation among programmers, especially in the past two years, fastjson has been targeted research, and more frequently reported vulnerabilities, a vulnerability does not matter, but the security team is always using email to urge the online application to upgrade the dependency, which can be fatal, I believe that many people are also unbearable, consider using other serialization framework to replace fastjson.

Go os/exec Short Tutorial

The Go standard library provides convenient methods to run external commands easily. Generally we use the methods under the os/exec package to execute external commands and interact with external commands. os/exec wraps the os.StartProcess method for easier access to input and output, providing I/O pipe and other features. I will dedicate two articles to Go’s methods for starting new processes and executing external commands, this is the first one, dedicated to the os/exec library.

PostgreSQL Jsonpath Usage in Practice

jsonpath is a tool used to parse json data, similar to xpath, jsonpath can parse very complex json data. PostgreSQL json development history. postgreSQL has supported json data type since 9.2, but due to the poor performance of parsing json data, it is not favored by everyone, but choose to use nosql database instead. So from pg9.4 onwards, the jsonb data type was supported. Compared to the json type, jsonb does not need to be parsed every time it is used, so the performance is much improved, and it also supports index queries and so on.

Using Gomock for Unit Testing in Go

In real projects, when you need to do unit testing. But often you find that there are a lot of dependencies. That’s where Gomock comes in handy! Gomock is an official mock framework for the Go language Installation 1 2 $ go get -u github.com/golang/mock/gomock $ go install github.com/golang/mock/mockgen Step 1: We will install the gomock third-party library and the mock code generation tool, mockgen, which will save us a lot of work.

Rsync Usage Tutorial

1. Introduction rsync is a commonly used Linux application for file synchronization. It can synchronize files between the local computer and a remote computer, or between two local directories (but does not support synchronization between two remote computers). It can also be used as a file copying tool, replacing the cp and mv commands. The r in its name refers to remote, rsync actually means “remote synchronization”. Unlike other file transfer tools (such as FTP or scp), rsync’s main feature is that it checks the existing files of both the sender and the receiver and only transfers the parts that have changed (the default rule is that the file size or modification time has changed).

Hadoop and Hive Development Environment Build on Windows10

There are numerous problems with the installation and operation of components such as Hadoop and Hive on Windows systems With the help of several Internet references, I completed the construction of Hadoop and Hive development environment on Windows 10. This article documents the specific steps, problems encountered, and corresponding solutions for the entire build process. Environmental Preparation Software Version Description Windows 10 Operating System JDK 8 Do not use a version greater than or equal to JDK9 for the time being, because unknown exceptions will occur when starting the virtual machine MySQL 8.

Several Ways to Stop Goroutine in Golang

goroutine case In our daily work, we often have code that starts a goroutine using the go keyword. 1 2 3 4 5 6 7 8 func main() { ch := make(chan string, 6) go func() { for { ch <- "Hello" } }() } A first-time goroutine developer may think it’s over, but after running for a while, he may run into some problems and struggle to figure out…

Easily Print Web Pages And Generate Pdf Documents

chromedp is a faster and simpler Go library that supports the Chrome DevTools Protocol, it is one of the most popular headless browser libraries, you can use it to do a lot of tasks that can only be performed through the browser, such as web screenshots, web rendering tests, downloading videos, simulating login, etc. Today Today I’m going to introduce a useful and simple feature: generating a pdf screenshot of

Installing Redis Object Cache for Litespeed Server

Redis is an efficient object caching application. If you have a Wordpress site based on Litespeed (OpenLitespeed) server and you have LSCache installed, you can further speed up your site with an object cache. However, you can only choose to install one of the object cache programs, Redis and Memcached. For Litespeed/Wordpress systems, there is not much difference in performance between the two as object cache programs. Today we will cover how to install a Redis server.

Building a Docker Private Registry

Registry Classification Sponsor Registry: a third-party registry for customers and communities Mirror Registry: third-party registry, only available to users Vendor Registry: The registry provided by the vendor that published the image Private Registry: Private registry with fire period and extra security layer (ssl) Why you need a private registry Generally deployed locally self-built (using intranet), if you use aliyun directly use the registry of ali can be. Hosted Mirror Low bandwidth consumption Fast download speed Rapid Deployment Install docker-registry To install registry in ubuntu 16.

Zabbix5.0 Detailed Installation Steps

zabbix Version 5.0 seems to have recently updated not long ago, we deployed to see what changes have not, then again. From 2.0 to 3.0 does look a lot better, today to see what 5.0 looks like, without further ado, start the installation! 5.0 new features reference https://www.zabbix.com/cn/whats_new_5_0 Prepare the environment Centos 7.8 PHP 7.2 + Apache 1.3.12 + Mysql or MariaDB 5.7+ Refer to the link https://www.zabbix.com/documentation/current/manual/installation/requirements for specific requirements

Use of the Go Empty Struct

1 Does an empty structure take up space? In Go, we can use unsafe.Sizeof to calculate the number of bytes an instance of a data type needs to occupy. 1 2 3 4 5 6 7 8 9 10 package main import ( "fmt" "unsafe" ) func main() { fmt.Println(unsafe.Sizeof(struct{}{})) } Running the above example will output: 1 2 $ go run main.go 0 That is, an instance of the empty struct struct{} does not occupy any memory space.

Memory Leak Monitoring on Flutter

The dart language used by Flutter has a garbage collection mechanism, and with garbage collection, memory leaks are inevitable. There is a memory leak detection tool LeakCanary on the Android platform that can easily detect if the current page is leaking in a debug environment. This article will take you through the implementation of a flutter-ready LeakCanary and tell you how I used it to detect two leaks on the 1.

How to Import Local Packages Using Go Module

go module is the official version management tool introduced after Go 1.11, and since Go 1.13, go module has been the default dependency management tool for the Go language. Since Go 1.14, the go modules feature has been officially recommended for use in production environments. Here is a detailed description of how to use the go module to import local packages. Prerequisites Suppose we now have two packages, moduledemo and mypackage, where the moduledemo package will import the mypackage package and use its New method.

Go Embed Brief Tutorial

Go compiles programs that are perfect for deployment, and if no other libraries are referenced through CGO, we generally compile executable binaries that are single files, perfect for copying and deployment. In practice, in addition to binaries, you may also need some configuration files, or static files, such as html templates, static images, CSS, javascript, etc. How these files can also be typed into the binary would be fantastic, and we could just copy and follow the single executable.

Android Simulation Positioning Implementation Details

In navigation test scenarios often need location simulation and route playback, recorded through the LocationManager.setTestProviderLocation() method to achieve simulated status, if the application to be tested does not support TestProviderLocation simulation location input, you can consider starting with the HAL layer, the hook the system’s default GPS implementation. 1, Android simulation permission open configuration In the version of Android 6.0 or below, you need to check the switch of simulated positioning in the settings, in 6.