Some Tips for Using Json in Go

This article summarizes the problems and solutions I usually encounter in my projects regarding the interconversion between go language JSON data and structs. Basic Serialization First let’s look at the basic usage of json.Marshal() (serialization) and json.Unmarshal (deserialization) in the Go language. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 type Person struct { Name string Age int64 Weight float64 } func main() { p1 := Person{ Name: "Qimi", Age: 18, Weight: 71.

Write a Springboot Shell Script

As a Java developer, you will use SpringBoot to develop Web applications in many scenarios, and the current microservices mainstream SpringCloud components are also built based on SpringBoot. The SpringBoot application is deployed to the server and requires an O&M script. In this article, we try to summarize the shell scripts used in production before and write a reusable SpringBoot application operation and maintenance script based on our experience, thus

Learn React hooks easily: useEffect() as an example

Recently I’ve come to realize that React hooks are very useful and I’ve reacquainted myself with the React framework. Here’s how to understand hooks properly, and to analyze useEffect(), one of the most important hooks, in depth. The content will be as common as possible, so that friends who are not familiar with React can also read. React’s two sets of APIs Previously, there was only one set of React API, but now there are two: the class API and the function-based hooks API.

The Underlying Implementation of Annotations in the Jdk

Using Java for several years, annotations are a common type, especially in some frameworks will be a lot of annotations to do component identification, configuration or strategy. But has not been deeply to explore the JDK annotations in the end what is the bottom is how to achieve? So refer to some information, to do a slightly more detailed analysis. JDK annotations description Refer to JLS-9.6 inside JavaSE-8 for a description of the annotations as follows.

Installing SonarQube in Centos7

SonarQube is a code quality management open platform that integrates thousands of automatic static code analysis rules designed to improve the quality and security of developers’ code, enabling developers to write cleaner, safer code. Three main and larger features are provided. Code reliability support: catch and alert errors in code in advance, thus avoiding undefined behaviors affecting end users. Application Security Support: Fixes vulnerabilities that could compromise applications and learns AppSec through security hotspots (simply understood to mean that it will learn and identify new vulnerabilities).

About Service Worker and Pwa

Service Worker is a script that the browser runs in the background independent of the web page. A PWA (Progressive Web App) is a web application, but similar in look and feel to a native app. Before we talk about Service Worker and PWA, let’s take a brief look at what Web Worker is. Web Worker What is Web Worker? The Web Worker is a built-in thread in the browser

Fixing the Problem of Lost Code After Git Revert and Merge Again

Our project uses GitLab for code management, and when I upgraded the system to SpringBoot 2.0, the branch was merged to the Master branch. During the actual deployment, I found that a child dependency of a two-party package that I depended on had not been upgraded, causing a service to fail to drop through. Since it took time to fix the bipartite package, we decided to Revert the Master branch in order not to affect the subsequent release of other features.

How to Perfectly Copy Base64 Images to the System Pasteboard

I recently came across a small knowledge point during development. Here is a Base64 encoded image that I want to copy into the system pasteboard, how can I solve this? For example, here is a picture. I can convert to Base64 encoding by using the Base64 conversion tool at https://www.base64-image.de/ and the result is as follows. An image is something like data:image/png;base64,ivBor2… Such encoding. Q: Now I have an image in this format, how can I copy it into the system pasteboard?

Spring Event Publishing and Listening Mechanism

Spring provides the ApplicationContext event mechanism to publish and listen to events, which is a very useful feature. Spring has some built-in events and listeners, such as before the Spring container starts, after the Spring container starts, after the application fails to start, etc. The listeners on these events will respond accordingly. Of course, we can also customize our listeners to listen to Spring’s original events. Or we can customize

The Popular Java Json Library Jackson

Jackson is a JSON (return) serialization tool in the Java ecosystem, which is efficient, powerful, and secure (without as many security vulnerabilities as Fastjson). It is also widely used, with Spring Boot/Cloud, Akka, Spark and many other frameworks using it as the default JSON processing tool. Dependency To use Jackson, you need to add the following dependencies to your project (note: you don’t need to add them manually when using

Running Go Generic Code Locally

Last year Ian Lance Taylor and Robert Griesemer released a new draft of Go generics (The Next Step for Generics), and the response from Gopher at home and abroad was overwhelming, with everyone interpreting the draft and this article, and feeling that this version of Go generic design is basically close to Go’s generic goals, and in short, much better than the previous one. Ian also provided an online compilation tool, go2go, to get a taste of Go generic programming.

Spring-Cloud-Gateway Custom Gateway Filter

The scope of GatewayFilter is the specified routing configuration, and the routing configuration options require filters to specify the list of GatewayFilters that you want to use. We can customize the GatewayFilter to do additional extensions to achieve some functionality that does not exist in the built-in GatewayFilter and apply it to our routing configuration. How to customize GatewayFilter To customize GatewayFilter, you need to implement the org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory interface, and the definition of GatewayFilterFactory is as follows.

Fetch Api Tutorials

fetch() is an upgraded version of XMLHttpRequest used to make HTTP requests inside JavaScript scripts. The browser provides this object natively. This article describes its usage in detail. 1. Basic usage The function of fetch() is basically the same as XMLHttpRequest, but with three main differences. fetch() uses Promise and does not use a callback function, so it is much simpler to write and more concise. The modular design of fetch(), with API spread over multiple objects (Response object, Request object, Headers object), is more reasonable; in contrast, the API design of XMLHttpRequest is not very good, with input, output and state all managed in the same interface, making it easy to write very confusing code.

Be Aware of Security Vulnerability Caused by Spring Boot Actuator

Recently, we have been particularly disturbed by various security vulnerabilities, and we have received dozens of vulnerability emails scanned by the security team in a week, which have a class of vulnerabilities that are easy to ignore, but have an extremely wide impact and are extremely harmful, and you should not be unfamiliar with my name, which is Spring Boot Actuator. Before writing this article, I did a little survey with my friends asking them about their knowledge of the Spring Boot Actuator and the results were surprisingly consistent, everyone knows that Spring Boot provides automatic configuration of the spring-boot-starter-actuator, but very few people but few people actually use its related features.

Sqlx Library Usage Guide

In projects we may usually use database/sql to connect to MySQL databases. This article introduces the sqlx.In and DB.NamedExec methods in sqlx that you may have overlooked, with the help of an example of using sqlx to achieve bulk insert data. Introduction to sqlx In a project we may usually use database/sql to connect to a MySQL database. sqlx can be thought of as a superset of the Go language’s

Several Ways to Convert Struct to map[string]interface{}

This article describes the “pitfalls” you need to know when converting struct to map[string]interface{} in Go, and also some of the methods you need to know. We usually use struct in Go to store our data, for example, to store user information, we might define the following struct. 1 2 3 4 5 6 7 // UserInfo type UserInfo struct { Name string `json:"name"` Age int `json:"age"` } u1 := UserInfo{Name: "q1mi", Age: 18} struct to map[string]interface JSON serialization method Serialize u1 with JSON, then deserialize to map

Why Will Spring Remain One of the Best Platforms in the Cloud Native Era

Back in 2015, the keynote at the SpringOne 2015 conference in Washington was Cloud Native Enterprise. The slogan of that conference was also Cloud Native and the posters were all over the place with Cloud Native. You may wonder how you could call it Cloud Native when containers weren’t popular at that time. Although many people may not have the same understanding of Cloud Native, more and more people believe that “Cloud native is about culture, not containers”.

Certify Your Git Commits on Github With GPG

Because of the email-based identity verification feature of Git, you can easily fake being someone else to make a Commit. How do you ensure that the Commit is really a developer commit? This is where a special key, the GPG key, is needed for authentication. About GPG GNU Privacy Guard (GnuPG or GPG) is a cryptographic software for encrypting and signing communication content and managing keys for asymmetric cryptography. Asymmetric cryptography is a technique that you should have come across, and it is used in many fields.

Vite + React Component Development Practice

1. Vite brings the light It’s no exaggeration to say that Vite has brought an absolute revolution to the front-end. Or we can say that the integration of esbuild, Browser es modules, HMR, Pre-Bundling, and other advanced tools and ideas about JS compilation development in the community behind Vite has brought about a revolutionary changes. The main reason why Vite is faster is that esbuild does pre-bundles dependencies + browser native ESM dynamic compilation, which I won’t go into too much detail here

Introduction to Introspector for Java

This article mainly analyzes the usage of Introspector. Introspector is a tool class that deals specifically with JavaBean and is used to get the descriptors in JavaBean. The commonly used descriptor-related classes of JavaBean are BeanInfo, PropertyDescriptor, MethodDescriptor, BeanDescriptor, EventSetDescriptor and ParameterDescriptor. The following will slowly analyze how these classes are used, as well as some of the features of Introspector. What is JavaBean JavaBean is a special (actually, it’s okay to say ordinary, it’s not very special) class, mainly used to pass data information, the methods in this class are mainly used to access private fields, and the method names conform to some naming rules (fields are private, each field has Setter and Getter methods, methods and fields named to meet the first letter lower case hump naming ).