- 博客(662)
- 资源 (10)
- 收藏
- 关注
原创 记录一次GC日志
2023-06-18T16:34:08.834+0800: 3695369.240: [GC concurrent-cleanup-start]2023-06-18T16:34:08.838+0800: 3695369.243: [GC concurrent-cleanup-end, 0.0036311 secs]2023-06-18T16:35:03.842+0800: 3695424.247: [GC pause (G1 Evacuation Pause) (young), 0.0752280 se
2023-06-18 16:35:54 134
原创 Ubuntu安装ElasticSearch
es安装目录 /usr/share/elasticsearch。es日志目录 /var/log/elasticsearch。es配置文件 /etc/elasticsearch。将elasticSearch安装为服务并启动。
2023-04-01 15:21:18 294
原创 Golang使用协程和管道并发计算素数
1.单线程异步初始化待计算数据 intChannel2.多线程并发计算素数并写入 primeChannel3.单线程异步等待计算结束并关闭 exitChannel
2022-06-12 12:36:32 234
原创 Golang协程
package mainimport ( "fmt" "time")func test() { for i := 0; i < 5; i++ { fmt.Println("test ", i) time.Sleep(time.Second) }}func main() { // 开启一个协程 go test() // 主线程执行完毕后,协程会退出 // 主线程是一个物理线程,直接作用在CPU上,重量级线程,非常耗费CPU资源 // 协程是主线程开启的,是轻.
2022-05-22 21:10:36 103
原创 Golang单元测试
cal.gopackage mainfunc addUpper(n int) int { result := 0 for i := 0; i < 10; i++ { result += i } return result}cal_test.gopackage mainimport "testing"func TestAddUpper(t *testing.T) { result := addUpper(10) if result != 45 { ..
2022-05-22 20:13:15 77
原创 Golang读写文件
使用带缓冲区的方式读取文件package mainimport ( "bufio" "fmt" "io" "os")func main() { file, err := os.Open("/Users/shangyidong/Downloads/test.txt") if err != nil { fmt.Printf("open file error:%v\n", err) return } // 函数结束前关闭文件 defer file.Close() fmt
2022-05-22 16:45:53 676
原创 Golang类型断言
package mainimport "fmt"type Point struct { x int y int}func TypeJudge(items ...interface{}) { for i, x := range items { switch x.(type) { case bool: fmt.Printf("第%d个参数%v是bool类型\n", i, x) case int, int32, int64: fmt.Printf("第%d个参数%d是.
2022-05-22 15:27:03 221
原创 Golang接口
// 如果实现了接口里所有的方法,则为实现了改接口。否则没实现。。有点愚蠢type Usb interface { Start() Stop()}type Phone struct {}type Camera struct {}// Phone 实现了Usb里定义的所有的方法func (p Phone) Start() { fmt.Println("手机 start")}func (p Phone) Stop() { fmt.Println("手机 stop")}..
2022-05-15 18:43:54 116
原创 Golang继承
type Student struct { Name string Age int}func (s Student) test() { fmt.Println("student test....")}func (s Graduate) test() { fmt.Println("Graduate test....")}type Pupil struct { Student}type Graduate struct { Student}func main() {.
2022-05-15 15:56:50 201
原创 Windows安装MySQL服务并进行binlog解析
1.官网下载 MySQL Community ServerMySQL :: Download MySQL Community Server这里下载的是Windows (x86, 64-bit), ZIP Archive mysql-8.0.29-winx64.zip2.下载完成后将ZIP解压到 D:\Tools\mysql-8.0.29-winx64\3.初始化命令行执行 mysqld --initialize此时会在 D:\Tools\mysql-8.0.29-winx64\目录下
2022-05-02 18:04:01 2896
原创 Golang工厂模式
package modeltype Student struct { Name string Score int}package modeltype teacher struct { name string}func NewStudent(n string) *teacher { return &teacher{ name: n, }}package mainimport ( "fmt" "gitee/shang/awesomeProjec.
2022-04-18 20:53:59 119
原创 Golang中的方法
type A struct { Num int}// 给A类型绑定一个方法func (a A) test(args int) { fmt.Println("args:", args) // args: 45 a.Num = args fmt.Println(a) // {45} a是值拷贝,和main中的a1没有关系}// 给A类型指针绑定一个方法func (a *A) test1(args int) string { fmt.Println("test1 args:", ar..
2022-04-10 18:03:05 299
原创 Golang中的结构体
type User struct { Username string // 小写 非公开 password string Age int}func main() { // 结构体是值类型,非引用类型 var user User fmt.Printf("%p\n", &user) // 0xc000098180 fmt.Println(user) // { 0} user.Username = "admin" user.password = "..
2022-04-10 17:08:52 395
原创 Golang中的map
var map1 = make(map[string]interface{}) map1["aaa"] = "1111" map1["bbb"] = "222" map1["000"] = "333" fmt.Println(map1) // map[000:333 aaa:1111 bbb:222] // 转成JSON marshal, _ := json.Marshal(map1) fmt.Println(string(marshal)) // {"000":"333","aaa...
2022-04-09 19:22:42 289
原创 Golang常用代码块
// 字符串用逗号分隔,转成数字数组categoryIdParts := strings.Split(limitSellingQtyConfigTabs[0].CategoryIDs, ",")var categoryIds = make([]int, len(categoryIdParts))if len(categoryIdParts) > 0 { for categoryIdIndex := range categoryIdParts { if categoryIdParts[c.
2022-04-07 16:44:43 559
原创 Golang中数组和切片
package mainimport ( "fmt")func main() { // 数组 var num1 [3]int = [3]int{1, 2, 3} fmt.Println(num1) var num2 [3]int = [...]int{1, 2, 3} fmt.Println(num2) // 指定数组下标 var num3 [3]int = [...]int{2: 1, 0: 2, 1: 3} fmt.Println(num3) // 遍历数组 fo.
2022-04-05 20:10:28 245
原创 Golang中new&make&错误处理
package mainimport "fmt"func main() { num1 := 100 // 类型:int 值:100 指针:0xc00000a098 fmt.Printf("类型:%T 值:%v 指针:%v \n", num1, num1, &num1) // num2 为指针类型 num2 := new(int) // 类型:*int 值:0xc00000a0d0 指针:0xc000006030 指向的值:0 fmt.Printf("类型:%T 值:%v 指.
2022-04-05 11:56:28 424
原创 Golang字符串&时间相关函数
package mainimport ( "fmt" "strconv" "strings" "time")func main() { str := "hello上海" // 遍历含有中文的字符串 str1 := []rune(str) // h e l l o 上 海 for i := 0; i < len(str1); i++ { fmt.Printf("%c\t", str1[i]) } fmt.Println() // 字符串转byte数组 var b.
2022-04-05 11:11:57 461
原创 Golang中的defer
package mainimport "fmt"func sum(n1, n2 int) int { // 将defer后的语句压入一个独立的栈中(defer栈),暂时不执行。相应的值也会一起入栈 // 当函数执行完之后,再从defer栈中按先入后出顺序执行 defer fmt.Println("n1=", n1) defer fmt.Println("n2=", n2) n1++ n2++ sum := n1 + n2 fmt.Println("sum=", sum) retu.
2022-04-04 19:31:07 321
原创 Golang初始化和闭包
Golang 闭包func AddUpper() func(int) int { var n = 10 return func(i int) int { n = n + i return n }}func main() { fmt.Println("闭包") f := AddUpper() fmt.Println(f(1)) // 11 fmt.Println(f(2)) // 13}
2022-04-04 18:28:17 174
原创 Gorm入门-事务
参考文档事务 | GORM - The fantastic ORM library for Golang, aims to be developer friendly.func testTransaction(GLOBAL_DB *gorm.DB) { tx := GLOBAL_DB.Begin() tx.Table("t_test_user").Where("id = ?", 4).Update("name", "111") if true { // 回滚事务 //tx.Rollba.
2022-03-27 15:08:55 863
原创 Gorm入门-删除
参考 删除 | GORM - The fantastic ORM library for Golang, aims to be developer friendly. // 删除数据 https://gorm.io/zh_CN/docs/delete.html // 如果模型包含了一个 gorm.deletedat 字段(gorm.Model 已经包含了该字段),它将自动获得软删除的能力! // 拥有软删除能力的模型调用 Delete 时,记录不会被数据库。但 GORM 会将 DeletedAt
2022-03-27 14:14:03 2638
原创 Gorm入门-更新
参考文档https://gorm.io/zh_CN/docs/update.html// update只更新选择的字段// updates 更新左右字段,两种形式:Map & 结构体,结构体零值不参与更新// save无论如何都更新所有内容,包括零值firstUser := TestUser{}GLOBAL_DB.First(&firstUser)updateUser := TestUser{}updateUser.ID = firstUser.IDupdateUs
2022-03-27 13:49:50 711
原创 Gorm入门-创建&查询
初始化go mod项目[ 9:56PM ] [ shangyidong@shangyidongdeiMac:~/go/src/awesomeProject ]$ go mod init gitee/shang/awesomeProjectgo: creating new go.mod: module gitee/shang/awesomeProjectgo: to add module requirements and sums: go mod tidy设置GOPROXY
2022-03-27 13:07:31 1729
原创 Java锁消除
锁消除(Lock Elimination)锁消除即删除不必要的加锁操作。根据代码逃逸技术,如果判断到一段代码中,堆上的数据不会逃逸出当前线程,那么可以认为这段代码是线程安全的,不必要加锁。public class Test { // java -server -XX:+DoEscapeAnalysis -XX:+EliminateLocks -XX:-UseBiasedLocking Test public static void main(String[] args) {
2021-08-24 22:11:11 533
原创 Windows Nodejs 环境安装
这里写自定义目录标题下载安装包下载安装包https://nodejs.org/en/download/安装到:D:\Program Files\nodejs 中在D:\Program Files\nodejs下新建两个文件夹 node-cache node-global新建一个系统变量NODE_HOME=D:\Program Files\nodejs在path中新增两项%NODE_HOME%%NODE_HOME%\node-global打开cmd执行npm config set p
2021-01-28 10:11:57 81
原创 微信小程序开发
后端数据库create table wx_backend;drop table if exists t_article;CREATE TABLE `t_article` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID', `article_id` varchar(64) NOT NULL ...
2020-05-05 10:54:11 287
原创 ElasticSearch聚合查询
ElasticSearch聚合查询1.group distinct参数:Set返回结果:Map<Long, Set>select distinct(playCategory) group by uid{ "from": 0, "size": 1, "query": { "bool": { "filter": [ { ...
2020-03-25 20:52:10 186
原创 Echarts笔记
1.平滑曲线图var colors = ['#5793f3', '#d14a61', '#675bba'];option = { "title":{ "text":"订单数量统计图", "subtext":"订单各种状态数量" }, "tooltip":{ "trigger":"axis", "...
2020-02-22 16:48:19 146
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人