创建型模式

1 创建型模式

  • 简单工厂模式(Simple Factory)
  • 单例模式(Singleton)
  • 工厂方法模式(Factory Method)
  • 抽象工厂模式(Abstract Factory)
  • 创建者模式(Builder)
  • 原型模式(Prototype)
2021-04-13    
设计模式:Options Pattern In Golang
Option模式
2021-03-29    
Apple Login

概述

这里记录了,接入AppleID登录,服务端的实现。

针对后端验证苹果提供了两种验证方式:

  • 一种是 基于JWT的算法验证
  • 一种是 基于授权码的验证
2021-03-19    
依赖注入wire

wire是Google开源的一款代码生成工具,通过依赖注入来自动链接不同的组件。

2021-03-10    
Go标准库atomic

在 Go 语言标准库中,sync/atomic包将底层硬件提供的原子操作封装成了 Go 的函数。但这些操作只支持几种基本数据类型,Go 语言在 1.4 版本的时候向sync/atomic包中添加了一个新的类型Value。此类型的值相当于一个容器,可以被用来“原子地"存储(Store)和加载(Load)任意类型的值。

2021-02-24    
Use Go Embed

Go1.16引入新的//go:embed指令,可以在编译时嵌入文件和目录,并对其进行访问。通过它,真正做到部署时只有一个二进制文件。

背景:2021-02-16,Go Team正式发布了Go1.16。该版本包含下面的一些重要变化:

  • embed 包和 //go:embed 指令
  • 增加对 macOS ARM64 的支持
  • 默认启用 Module
  • io/fs 包
  • 弃用io/ioutil

最后,还有许多其他改进和错误修复,包括构建速度提高了 20-25%,linux/amd64上内存使用量减少了 5-15%。有关更改的完整列表以及有关上述改进的更多信息,请参阅 Go 1.16 发行说明

2021-02-19    
区分换行符

CRLF, LF 是用来表示文本换行的方式。CR(Carriage Return) 代表回车,对应字符 '\r';LF(Line Feed) 代表换行,对应字符 '\n'。不同的操作系统文本使用的换行符各不相同。

Windows 系统使用的是 CRLF, Unix系统(包括Linux, MacOS近些年的版本) 使用的是LF。

区分识别换行符

那么如何在命令行中,显示区分到底使用的是那个换行符,是CRLF,还是LF?可以使用下面几种工具:

  • less
  • cat
  • file

1. file -k

通过命令 file -k demo.txt .

  • 对于DOS/Windows 换行符, 会输出: with CRLF line terminators

  • 对于MAC换行符,会输出:with LF line endings

  • 对于Linux/Unix ”CR“, 则只会输出 text

2. cat -e

cat -e 将Linux/Unix 换行符(\n 或 LF) 显示成 $, Dos/Windows换行符(\r\n 或者 CRLF)显示成 ^M$, 如:

--CRLF
$ cat -e 2020654103_2020-12-18.csv
LQH2HPN4R7MDRL,63036NC00-015-G,EY00875,2020654103,12000,12000^M$
DLW21HN900SQ2L,720400201-015-H,EY00H61,2020653533,300000,300000^M$
DLW21HN181SQ2L,720402M00-015-H,IZ00091,2020653533,18000,18000^M$

#LF
$ cat -e 2020654103_2020.csv
DLW21HN181SQ2L,720402M00-015-H,IZ00091,2020653533,18000,18000$
DLW21HN670HQ2L,720406000-015-H,IZ00339,2020653533,60000,60000$
DLW21HN670HQ2L,720406000-015-H,IZ00408,2020653533,24000,24000$

3. less -u

通过less -u 命令可以将 CR 显示成 ^M

2020-12-19    
Docker搭建FTP服务器

使用Docker搭建FTP服务。使用的镜像是fauria/vsftpd

1. 拉取镜像

docker pull fauria/vsftpd

2. 运行镜像

docker run -d --name vsftpd -v ~/sftp:/home/vsftpd  \
-p 21:21 -p 20:20 -p 21100-21110:21100-21110 \
-e FTP_USER=myuser -e FTP_PASS=mypass \
-e PASV_ADDRESS=127.0.0.1 \
--restart=always \
fauria/vsftpd

#-p 进行端口绑定映射
#-v 添加容器数据卷
#-e FTP_USER=davion -e FTP_PASS=davion 添加一个初始化用户davion
#PASV_MIN_PORT和PASV_MAX_PORT映射的是被动模式下端口使用范围
#-name vsftpd 为容器命名为vsftpd
#--restart=always fauria/vsftpd docker 异常退出时自动重启容器

3. 在镜像中新增自定义的新用户

# 进入容器
docker exec -it vsftpd bash

# 创建
mkdir /home/vsftpd/myuser
echo -e "myuser\nmypass" >> /etc/vsftpd/virtual_users.txt
/usr/bin/db_load -T -t hash -f /etc/vsftpd/virtual_users.txt /etc/vsftpd/virtual_users.db
exit

#重启
docker restart vsftpd

4. 访问

在浏览器(或者其他ftp客户端工具)中输入:ftp://127.0.0.1 , 测试是否访问正常

2020-11-29    
@Bean和@Component

@Component and @Bean do two quite different things, and shouldn’t be confused.

@Component (and @Service and @Repository) are used to auto-detect and auto-configure beans using classpath scanning. There’s an implicit one-to-one mapping between the annotated class and the bean (i.e. one bean per class). Control of wiring is quite limited with this approach, since it’s purely declarative.

@Bean is used to explicitly declare a single bean, rather than letting Spring do it automatically as above. It decouples the declaration of the bean from the class definition, and lets you create and configure beans exactly how you choose.

2020-10-07    
Mysqldump
读书笔记
2020-08-07