[ go-zero微服务项目搭建[go-zero框架] ]


Go-zero微服务框架

一. 安装

...请自行查看文档安装

二. 项目配置

  1. 配置gopath环境变量
  2. 在src目录下创建项目文件mscoin
    • ucenter就是rpc服务
    • ucenter-api就是api服务
    • grpc-common就是rpc服务公用的文件
    • mscoin-common就是api服务公用的文件
  3. 创建好上述4个文件夹(每个文件夹里面执行go mod init)
  4. 回到mscoin文件夹执行 go work init创建工作, 再添加文件夹
    • go work use ./ucenter
    • go work use ./ucenter-api
    • go work use ./grpc

< Read more >

[ etcd[golang]服务发现 ]


github官方

官方文档

配置文件yaml

conf1.yaml

# 结点名称
name: "s1"

# 数据存储目录
data-dir: "/etcd-data"

# 集群提供给外部客户端访问的url, 即外部客户端必须通过指定
listen-client-urls: "http://0.0.0.0:2379"

# 想客户端发布的服务端点
advertise-client-urls: "http://42.193.152.252:2379"

# 集群成员之间通信使用的url
listen-peer-ur

< Read more >

[ zap日志[go] ]


基本使用

package main

import (
    "os"

    "github.com/natefinch/lumberjack"
    "go.uber.org/zap"
    "go.uber.org/zap/zapcore"
)

type Logger struct {
    *zap.Logger
}

func ZapLoginit() *Logger {
    coreList := make([]zapcore.Core, 0)
    // 输出终端
    encod

< Read more >

[ 视频爬虫[python] ]


简单版本

1.案例网站

https://www.ikanbot.com/play/810009

爬取思路 - 查看网络请求情况 2 - 找到M3u8文件 3 - 获取m3u8文件请求地址 4 - 获取文件里面ts视频的请求地址 5

2.python爬虫 同步版本

import requests
import re
import os
header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1

< Read more >

[ 断言,判断类型[golang] ]


判断变量类型

  • 使用reflect标准库

案例: 获取结构体里, 每个字段的类型type, 名字name, 值value

package main

import (
    "fmt"
    "reflect"
)

type User struct {
    Id   int
    Name string
}

func (u *User) Call() {
    fmt.Println("user is called ..")
    fmt.Printf("%v\n", u)
}

func To

< Read more >

[ go-rpc[原生] ]


原生的rpc服务

client.go

package main 

import (
    "fmt"
    "net/rpc"
)

type Request struct {
    Num1 int
    Num2 int
}

type Response struct {
    Num int
}

func main() {
    req := Request{Num1: 1, Num2: 2}
    client, err := rpc.DialHTTP("tcp", ":8080") //

< Read more >