当前位置:   article > 正文

开发个人Ollama-Chat--4 用户管理_ollama webui用户如何管理

ollama webui用户如何管理

开发个人Ollama-Chat–4 用户管理

先看下我的目录结构,可以根据个人爱好,进行重构

|-- Dockerfile
|-- LICENSE
|-- common
|   |-- callmodel
|   |   |-- gemma.go
|   |   `-- models.go
|   |-- consts
|   |   |-- code.go
|   |   |-- common.go
|   |   |-- config.go
|   |   `-- consts.go
|   |-- cryptx
|   |   `-- crypt.go
|   |-- curlhttp
|   |   `-- curl.go
|   |-- database
|   |   |-- common.go
|   |   |-- connect.go
|   |   |-- dao.go
|   |   |-- ormLogx.go
|   |   |-- redisClient.go
|   |   `-- redisDao.go
|   |-- go.mod
|   |-- go.sum
|   |-- jwtx
|   |   `-- jwt.go
|   |-- middleware
|   |   `-- static.go
|   |-- model
|   |   |-- chat.sql
|   |   |-- chatmodel.go
|   |   |-- chatmodel_client.go
|   |   |-- prompt.sql
|   |   |-- promptmodel.go
|   |   |-- promptmodel_client.go
|   |   |-- readMe.md
|   |   |-- user.sql
|   |   |-- usermodel.go
|   |   `-- usermodel_client.go
|   `-- utils
|       `-- utils.go
|-- docker-compose.yaml
|-- nginx
|   `-- conf.d
|       `-- default.conf
|-- readme.md
`-- service
    |-- chat
    |   |-- api
    |   `-- rpc
    `-- user
        |-- api
        `-- rpc

  • 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
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54

4.1 生成 user model 模型

  • 创建 sql 文件 OpenUI 前端需要的字段,不可缺少。mysql服务需提前创建 openui库, user table

    CREATE TABLE `user` (
                            `id` bigint unsigned NOT NULL AUTO_INCREMENT,
                            `name` varchar(255)  NOT NULL DEFAULT '' COMMENT '用户姓名',
                            `email` varchar(255)  NOT NULL DEFAULT '' COMMENT '用户电话',
                            `password` varchar(255)  NOT NULL DEFAULT '' COMMENT '用户密码',
                            `role` varchar(264)  NOT NULL DEFAULT '' COMMENT '用户角色',
                            `profile_image_url` varchar(255)  NOT NULL DEFAULT '' COMMENT '用户头像',
                            `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
                            `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                            PRIMARY KEY (`id`),
                            UNIQUE KEY `idx_email_unique` (`email`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4;
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
  • 运行模板生成命令 model文件放置在通用目录,和go-zero官方案例不同

    goctl model mysql ddl -src ./model/user.sql -dir ./model -c
    
    • 1

4.2 生成 user api 服务

前缀,路由,传参,响应不可变,否则 openui调用失败

  • 创建 user.api 文件

    type (
    	// 用户登录
    	LoginRequest {
    		Email    string `json:"email"`
    		Password string `json:"password"`
    	}
    	LoginResponse {
    		Id              int64  `json:"id"`
    		Name            string `json:"name"`
    		Role            string `json:"role"`
    		ProfileImageUrl string `json:"profile_image_url"`
    		Token           string `json:"token"`
    	}
    	// 用户登录
    	// 用户注册
    	RegisterRequest {
    		Name            string `json:"name"`
    		Email           string `json:"email"`
    		Password        string `json:"password"`
    		ProfileImageUrl string `json:"profile_image_url"`
    	}
    	RegisterResponse {
    		Id    int64  `json:"id"`
    		Name  string `json:"name"`
    		Token string `json:"token"`
    	}
    	// 用户注册
    	// 用户信息
    	UserInfoResponse {
    		Id              int64  `json:"id"`
    		Name            string `json:"name"`
    		Email           string `json:"email"`
    		Role            string `json:"role"`
    		ProfileImageUrl string `json:"
    profile_image_url"`
    	}
    // 用户信息
    )
    
    @server (
    	prefix: /api/v1
    )
    service User {
    	@handler Login
    	post /auths/signin (LoginRequest) returns (LoginResponse)
    
    	@handler Register
    	post /auths/signup (RegisterRequest) returns (RegisterResponse)
    }
    
    @server (
    	jwt:    Auth
    	prefix: /api/v1
    )
    service User {
    	@handler UserInfo
    	get /auths returns (UserInfoResponse)
    }
    
    
    • 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
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
  • 运行模板生成命令

    goctl api go -api ./api/user.api -dir ./api
    
    • 1

4.3 生成 user rpc 服务

  • 创建 user.proto文件

    syntax = "proto3";
    
    package userclient;
    
    option go_package = "./user";
    
    // 用户登录
    message LoginRequest {
        string Email = 1;
        string Password = 2;
    }
    message LoginResponse {
        int64 Id = 1;
        string Name = 2;
        string Token = 3;
        string Role = 4;
        string ProfileImageUrl = 5;
    }
    // 用户登录
    
    // 用户注册
    message RegisterRequest {
        string Name = 1;
        string Email = 2;
        string Password = 3;
        string ProfileImageUrl = 4;
    }
    message RegisterResponse {
        int64 Id = 1;
        string Name = 2;
        string Token = 3;
    }
    // 用户注册
    
    // 用户信息
    message UserInfoRequest {
        int64 Id = 1;
    }
    message UserInfoResponse {
        int64 Id = 1;
        string Name = 2;
        string Email = 3;
        string Role = 4;
        string ProfileImageUrl = 5;
    }
    // 用户信息
    
    service User {
        rpc Login(LoginRequest) returns(LoginResponse);
        rpc Register(RegisterRequest) returns(RegisterResponse);
        rpc UserInfo(UserInfoRequest) returns(UserInfoResponse);
    }
    
    
    • 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
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
  • 运行模板生成命令

    goctl rpc protoc ./rpc/user.proto --go_out=./rpc/types --go-grpc_out=./rpc/types --zrpc_out=./rpc
    
    • 1

4.3 配置文件

  • rpc/etc

    Name: user.rpc
    ListenOn: 0.0.0.0:9001
    
    Etcd:
        Hosts:
            - xxxxxxxxxxxxxxxxxxxxxxxxx:2379
        Key: user.rpc
    
    Timeout: 0
    
    Mysql:
        Host: xxxxxxxxxxxxxx
        Port: 3306
        DbName: openui
        User: xxxxxx
        Password: "xxxxxxxxxxxxxxxxxxxxxxxxx"
        DBZone: "TS"
        Charset: utf8mb4
        MaxIdle: 10
        MaxOpen: 100
        LogMode: true
        Loc: Asia/Shanghai
        Debug: true
        TablePrefix: "v1_"
        MaxLifetime: 300
    
    # redis 支持选择db, 不使用go-zero官方库
    CacheRedis:
        Name: "openui"
        Nettype: "tcp"
        Address: "redis:6379"
        Auth: ""
        DB: 0
    
    Salt: ********************
    
    #日志配置
    LogConf:
        ServiceName: user.rpc
        Mode: file
        TimeFormat: 2006-01-02 15:04:05.000
        Path: logs
        Level: info
        Compress: true
        Stat: false # 不记录CPU、内存等信息
        KeepDays: 10
        MaxBackups: 2
    
    
    • 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
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
  • api/etc

    Name: user.rpc
    ListenOn: 0.0.0.0:9001
    
    Etcd:
        Hosts:
            - xxxxxxxxxxxxxxxxxxxxxxxxx:2379
        Key: user.rpc
    
    Timeout: 0
    
    Mysql:
        Host: xxxxxxxxxxxxxx
        Port: 3306
        DbName: openui
        User: xxxxxx
        Password: "xxxxxxxxxxxxxxxxxxxxxxxxx"
        DBZone: "TS"
        Charset: utf8mb4
        MaxIdle: 10
        MaxOpen: 100
        LogMode: true
        Loc: Asia/Shanghai
        Debug: true
        TablePrefix: "v1_"
        MaxLifetime: 300
    # redis 支持选择db, 不使用go-zero官方库
    CacheRedis:
        Name: "openui"
        Nettype: "tcp"
        Address: "redis:6379"
        Auth: ""
        DB: 0
    
    Salt: *****************
    
    #日志配置
    LogConf:
        ServiceName: user.rpc
        Mode: file
        TimeFormat: 2006-01-02 15:04:05.000
        Path: logs
        Level: info
        Compress: true
        Stat: false # 不记录CPU、内存等信息
        KeepDays: 10
        MaxBackups: 2
    
    
    • 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
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

4.4 业务处理

  • 业务处理就不过多描述了,具体处理流程可以看相应文件的实现

项目地址

jackwillsmith/openui-svelte-build (github.com)
GitHub - jackwillsmith/openui-backend-go: openui-backend-go

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/882293?site
推荐阅读
相关标签
  

闽ICP备14008679号