Skip to content

honlyc/openim-cmdline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openim-cmdline

Command line tool for OpenIM

Installation

Install openim-cmdline

go install github.com/honlyc/openim-cmdline/openim

Dependencies

install protoc-gen-go-grpc

go install google.golang.org/grpc/cmd/protoc-gen-go-grpc

install protoc-gen-go-http

go install github.com/honlyc/openim-cmdline/protoc-gen-go-http

install protoc

docs: https://grpc.io/docs/protoc-installation/

Mac:

brew install protobuf

Quick Start

Generation Client

auth.proto

syntax = "proto3";
package OpenIMCmdLine.auth;
option go_package = "github.com/honlyc/openim-cmdline/protocol/auth";

import "google/api/annotations.proto";
import "options/openim.proto";

message userTokenReq {
  string secret = 1;
  int32  platformID = 2;
  string userID = 3;
}
message userTokenResp {
  string token = 2;
  int64  expireTimeSeconds = 3;
}

message getUserTokenReq{
  int32  platformID = 1;
  string userID = 2;
}

message getUserTokenResp{
  string token = 1;
  int64  expireTimeSeconds = 2;
}

service Auth {
  // 路由内校验 token
  option (openim.server).token = true;
  
  //生成token
  rpc userToken(userTokenReq) returns(userTokenResp){
    option (google.api.http) = {
      post: "/auth/user_token",
      body: "*"
    };
  };
  // 管理员获取用户 token
  rpc getUserToken(getUserTokenReq)returns(getUserTokenResp){
    option (google.api.http) = {
      post: "/auth/get_user_token",
      body: "*"
    };
    // path 内校验 Token
    option (openim.method).token = true;
  };
}
openim proto client auth/auth.proto -- --proto_path=/usr/local/include/

Use HTTP and GRPC

r := gin.New()
// get Token Parser by Gin HandlerFunc
ParseToken := GinParseToken(config)
authApi := NewAuthApi(*authRpc)
auth.RegisterAuthHTTPServer(r, ParseToken, &authApi)

Optimization for OpenIMServer

a := NewAuthApi(*authRpc)

// Before ⬇️
authRouterGroup := r.Group("/auth")
{
	authRouterGroup.POST("/user_token", a.UserToken)
	authRouterGroup.POST("/get_user_token", ParseToken, a.GetUserToken)
	authRouterGroup.POST("/parse_token", a.ParseToken)
	authRouterGroup.POST("/force_logout", ParseToken, a.ForceLogout)
}

// After ⬇️
auth.RegisterAuthHTTPServer(r, ParseToken, &a)

About

Command line tool for OpenIM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published