Logo ByteGopher
  • English
    中文
Logo Inverted Logo
  • Posts
  • Blog
  • CloudNative
  • Infrastructure
    • TimeSeriesDB
  • Kubernetes
  • Note C
  • Note Go
  • React
  • Tips
  • Nodus
  • Interview
  • Life
  • Linux
Hero Image
【Linux】 Systemd

1# 通过Pid获取对应的service 2systemd status <Pid>

January 1, 0001 Read
Hero Image
【慕课网】Go开发短地址服务

1 短地址服务 将长地址缩短到一个很短的地址,用户访问这个短地址可以重定向到原本的长地址。 如何设计HTTP Router 和handler 如何在HTTP 处理流程中加入Middleware 如何利用Go的Interface来实现可扩展的设计 如何使用redis的自增长序列生成短地址 2 主服务模块 API接口 POST /api/shorten GET /api/info?shortlink=shortlink GET /:shortlink - return 302 code 重定向 POST /api/shorten Params Name Type Description url string Required. URL to shorten. e.g. https://www.example.com expiration_in_minutes int Required. Expiration of short link in minutes. e.g. value 0 represents permanent. Response 1{ 2 "shortlink":"P" 3} GET /api/info?shortlink=shortlink Params Name Type Description shortlink string Required. Id of shortened. e.g. P Response

January 1, 0001 Read
Hero Image
2021-03-12

Golang 以下代码的输出内容 1package main 2import ( 3 "fmt" 4) 5 6func main() { 7 deferCall() 8} 9func deferCall() { 10 defer func() { fmt.Println(">>> before") }() 11 defer func() { fmt.Println(">>> in process") }() 12 defer func() { fmt.Println(">>> done") }() 13 panic("<<< panic here") 14} 输出结果如下 1>>> done 2>>> in process 3>>> before 4panic: <<< panic here defer执行的顺序是后进先出, 压栈。当出现panic的时候,会按照defer的后进先出的顺序执行,最后才会执行panic。 defer是一个压栈过程。 这段代码的输出,以及原因 1package main 2 3import "fmt" 4 5func main() { 6 slice := []int{0, 1, 2, 3} 7 m := make(map[int]*int) 8 9 for key, val := range slice { 10 m[key] = &val 11 } 12 13 for k, v := range m { 14 fmt.

January 1, 0001 Read
Hero Image
2021-03-13

Golang 下面两段代码输出什么 1// 1. 2 func main() { 3 s := make([]int, 5) 4 s = append(s, 1, 2, 3) 5 fmt.Println(s) 6 } 7 8// 2. 9 func main() { 10 s := make([]int,0) 11 s = append(s,1,2,3,4) 12 fmt.Println(s) 13} 输出结果如下 1[0 0 0 0 0 1 2 3] 2[1 2 3 4] 使用make 新建 slice 会根据初始化的容量补0 这段代码的问题 1 func funcMui(x,y int)(sum int,error){ 2 return x+y,nil 3 } 有多个返回值的时候,返回值的名字要么全部省略,要么全部写上

January 1, 0001 Read
Hero Image
2021-03-14

Golang 使用channel实现简单并发,注意执行顺序 1package main 2 3import ( 4 "fmt" 5 "sync" 6 "time" 7) 8 9var wg sync.WaitGroup 10 11func printer(ch chan int) { 12 for i := range ch { 13 fmt.Printf("Received %d \n", i) 14 <-time.After(time.Second / 5) 15 fmt.Printf("Job %v done \n", i) 16 } 17 println("All Jobs done") 18 wg.Done() 19 println("Finished") 20} 21 22// main is the entry point for the program. 23func main() { 24 c := make(chan int) 25 go printer(c) 26 wg.

January 1, 0001 Read
Hero Image
2021-03-15

Golang 获取变量的数据类型 1package main 2 3import ( 4 "fmt" 5 "reflect" 6) 7 8func main() { 9 10 // string type : string 11 var1 := "hello world" 12 13 // integer : int 14 var2 := 10 15 16 // float : float64 17 var3 := 1.55 18 19 // boolean : bool 20 var4 := true 21 22 // shorthand string array declaration : []string 23 var5 := []string{"foo", "bar", "baz"} 24 25 // map is reference datatype : map[string]string 26 var6 := map[int]string{100: "Ana", 101: "Lisa", 102: "Rob"} 27 28 // complex64 and complex128 29 // is basic datatype : complex128 30 var7 := complex(9, 15) 31 32 // using %T format specifier to 33 // determine the datatype of the variables 34 35 fmt.

January 1, 0001 Read
Hero Image
2021-03-16

Golang 同时定义多个相关的struct, 这样写可读性更好一些 1type ( 2 // item defines the fields associated with the item tag 3 // in the rss document. 4 item struct { 5 XMLName xml.Name `xml:"item"` 6 PubDate string `xml:"pubDate"` 7 Title string `xml:"title"` 8 Description string `xml:"description"` 9 Link string `xml:"link"` 10 GUID string `xml:"guid"` 11 GeoRssPoint string `xml:"georss:point"` 12 } 13 14 // image defines the fields associated with the image tag 15 // in the rss document.

January 1, 0001 Read
Hero Image
2021-03-17

Golang 1// A map of registered matchers for searching. 2var matchers = make(map[string]Matcher) 3 4// Run performs the search logic. 5func Run(searchTerm string) { 6 // Retrieve the list of feeds to search through. 7 feeds, err := RetrieveFeeds() 8 if err != nil { 9 log.Fatal(err) 10 } 11 12 // Create an unbuffered channel to receive match results to display. 13 results := make(chan *Result) 14 15 // Setup a wait group so we can process all the feeds.

January 1, 0001 Read
Hero Image
2021-03-xx

Golang

January 1, 0001 Read
Hero Image
2021-04-20

Flush 清空缓冲区 首先,咱们设想要给鱼缸换水,所以需要一个水泵,水泵是连接鱼缸和下水道的,咱们的任务就是将鱼缸里面水全抽干,这时,我们就可以把水管当做缓冲区。如果咱们一见鱼缸里面水抽干了就立马关了水泵,这时会发现水管里还有来不及通过水泵流向下水道的残留水,我们可以把抽水当做读数据,排水当做写数据,水管当做缓冲区,这样就容易明白了。 那么这样一来我们如果中途调用close()方法,输出区也还是有数据的,就像水缸里有水,只是在缓冲区遗留了一部分,这时如果我们先调用flush()方法,就会强制把数据输出,缓存区就清空了,最后再关闭读写流调用close()就完成了。 缓冲区可以简单地理解为一段内存区域。可以简单地把缓冲区理解为一段特殊的内存。某些情况下,如果一个程序频繁地操作一个资源(如文件或数据库),则性能会很低,此时为了提升性能,就可以将一部分数据暂时读入到内存的一块区域之中,以后直接从此区域中读取数据即可,因为读取内存速度会比较快,这样可以提升程序的性能。 https://blog.csdn.net/qq_38129062/article/details/87115620

January 1, 0001 Read
Hero Image
2021-04-21

Flush 清空缓冲区 首先,咱们设想要给鱼缸换水,所以需要一个水泵,水泵是连接鱼缸和下水道的,咱们的任务就是将鱼缸里面水全抽干,这时,我们就可以把水管当做缓冲区。如果咱们一见鱼缸里面水抽干了就立马关了水泵,这时会发现水管里还有来不及通过水泵流向下水道的残留水,我们可以把抽水当做读数据,排水当做写数据,水管当做缓冲区,这样就容易明白了。 那么这样一来我们如果中途调用close()方法,输出区也还是有数据的,就像水缸里有水,只是在缓冲区遗留了一部分,这时如果我们先调用flush()方法,就会强制把数据输出,缓存区就清空了,最后再关闭读写流调用close()就完成了。 缓冲区可以简单地理解为一段内存区域。可以简单地把缓冲区理解为一段特殊的内存。某些情况下,如果一个程序频繁地操作一个资源(如文件或数据库),则性能会很低,此时为了提升性能,就可以将一部分数据暂时读入到内存的一块区域之中,以后直接从此区域中读取数据即可,因为读取内存速度会比较快,这样可以提升程序的性能。 https://blog.csdn.net/qq_38129062/article/details/87115620

January 1, 0001 Read
Hero Image
2021-05-20

1package main 2 3import "fmt" 4 5var testMap = map[string]map[string]struct { 6 Name string 7}{ 8 "first": {"second": {Name: "12312"}}, 9 "second": {"second": {"12312"}}, 10} 11 12func main() { 13 d := testMap["first"]["second"].Name 14 fmt.Printf("++-%v-++\n", d) 15 16 17 // map 不会报 nil 18 c := testMap["first22"]["second"].Name 19 fmt.Printf("++-%v-++\n", c) 20} 结果 1++-12312-++ 2++--++

January 1, 0001 Read
  • ««
  • «
  • 14
  • 15
  • 16
  • 17
  • 18
  • »
  • »»
Navigation
  • About
  • Skills
  • Recent Posts
  • My Story
Contact me:
  • renqiqiang@outlook.com

Stay up to date with email notification

By entering your email address, you agree to receive the newsletter of this website.

Toha Theme Logo Toha
© 2020-2022 Copyright.
Powered by Hugo Logo