feat: add openim docker

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
Xinwei Xiong (cubxxw)
2023-12-14 11:39:54 +08:00
parent a42a44e0a3
commit ad47590e13
36 changed files with 113 additions and 77 deletions
+7 -7
View File
@@ -9,7 +9,7 @@ import (
"net/http"
)
// API endpoints and other constants
// API endpoints and other constants.
const (
APIHost = "http://127.0.0.1:10002"
UserTokenURL = APIHost + "/auth/user_token"
@@ -18,27 +18,27 @@ const (
OperationID = "1646445464564"
)
// UserTokenRequest represents a request to get a user token
// UserTokenRequest represents a request to get a user token.
type UserTokenRequest struct {
Secret string `json:"secret"`
PlatformID int `json:"platformID"`
UserID string `json:"userID"`
}
// UserTokenResponse represents a response containing a user token
// UserTokenResponse represents a response containing a user token.
type UserTokenResponse struct {
Token string `json:"token"`
ErrCode int `json:"errCode"`
}
// User represents user data for registration
// User represents user data for registration.
type User struct {
UserID string `json:"userID"`
Nickname string `json:"nickname"`
FaceURL string `json:"faceURL"`
}
// UserRegisterRequest represents a request to register a user
// UserRegisterRequest represents a request to register a user.
type UserRegisterRequest struct {
Secret string `json:"secret"`
Users []User `json:"users"`
@@ -58,7 +58,7 @@ func main() {
}
}
// GetUserToken requests a user token from the API
// GetUserToken requests a user token from the API.
func GetUserToken(userID string) (string, error) {
reqBody := UserTokenRequest{
Secret: SecretKey,
@@ -88,7 +88,7 @@ func GetUserToken(userID string) (string, error) {
return tokenResp.Token, nil
}
// RegisterUser registers a new user using the API
// RegisterUser registers a new user using the API.
func RegisterUser(token, userID, nickname, faceURL string) error {
user := User{
UserID: userID,
+5 -5
View File
@@ -7,18 +7,18 @@ import (
"github.com/openimsdk/open-im-server/v3/test/e2e/framework/config"
)
// UserInfoRequest represents a request to get or update user information
// UserInfoRequest represents a request to get or update user information.
type UserInfoRequest struct {
UserIDs []string `json:"userIDs,omitempty"`
UserInfo *gettoken.User `json:"userInfo,omitempty"`
}
// GetUsersOnlineStatusRequest represents a request to get users' online status
// GetUsersOnlineStatusRequest represents a request to get users' online status.
type GetUsersOnlineStatusRequest struct {
UserIDs []string `json:"userIDs"`
}
// GetUsersInfo retrieves detailed information for a list of user IDs
// GetUsersInfo retrieves detailed information for a list of user IDs.
func GetUsersInfo(token string, userIDs []string) error {
url := fmt.Sprintf("http://%s:%s/user/get_users_info", config.LoadConfig().APIHost, config.LoadConfig().APIPort)
@@ -29,7 +29,7 @@ func GetUsersInfo(token string, userIDs []string) error {
return sendPostRequestWithToken(url, token, requestBody)
}
// UpdateUserInfo updates the information for a user
// UpdateUserInfo updates the information for a user.
func UpdateUserInfo(token, userID, nickname, faceURL string) error {
url := fmt.Sprintf("http://%s:%s/user/update_user_info", config.LoadConfig().APIHost, config.LoadConfig().APIPort)
@@ -44,7 +44,7 @@ func UpdateUserInfo(token, userID, nickname, faceURL string) error {
return sendPostRequestWithToken(url, token, requestBody)
}
// GetUsersOnlineStatus retrieves the online status for a list of user IDs
// GetUsersOnlineStatus retrieves the online status for a list of user IDs.
func GetUsersOnlineStatus(token string, userIDs []string) error {
url := fmt.Sprintf("http://%s:%s/user/get_users_online_status", config.LoadConfig().APIHost, config.LoadConfig().APIPort)
+8 -8
View File
@@ -11,29 +11,29 @@ import (
"github.com/openimsdk/open-im-server/v3/test/e2e/framework/config"
)
// ForceLogoutRequest represents a request to force a user logout
// ForceLogoutRequest represents a request to force a user logout.
type ForceLogoutRequest struct {
PlatformID int `json:"platformID"`
UserID string `json:"userID"`
}
// CheckUserAccountRequest represents a request to check a user account
// CheckUserAccountRequest represents a request to check a user account.
type CheckUserAccountRequest struct {
CheckUserIDs []string `json:"checkUserIDs"`
}
// GetUsersRequest represents a request to get a list of users
// GetUsersRequest represents a request to get a list of users.
type GetUsersRequest struct {
Pagination Pagination `json:"pagination"`
}
// Pagination specifies the page number and number of items per page
// Pagination specifies the page number and number of items per page.
type Pagination struct {
PageNumber int `json:"pageNumber"`
ShowNumber int `json:"showNumber"`
}
// ForceLogout forces a user to log out
// ForceLogout forces a user to log out.
func ForceLogout(token, userID string, platformID int) error {
url := fmt.Sprintf("http://%s:%s/auth/force_logout", config.LoadConfig().APIHost, config.LoadConfig().APIPort)
@@ -45,7 +45,7 @@ func ForceLogout(token, userID string, platformID int) error {
return sendPostRequestWithToken(url, token, requestBody)
}
// CheckUserAccount checks if the user accounts exist
// CheckUserAccount checks if the user accounts exist.
func CheckUserAccount(token string, userIDs []string) error {
url := fmt.Sprintf("http://%s:%s/user/account_check", config.LoadConfig().APIHost, config.LoadConfig().APIPort)
@@ -56,7 +56,7 @@ func CheckUserAccount(token string, userIDs []string) error {
return sendPostRequestWithToken(url, token, requestBody)
}
// GetUsers retrieves a list of users with pagination
// GetUsers retrieves a list of users with pagination.
func GetUsers(token string, pageNumber, showNumber int) error {
url := fmt.Sprintf("http://%s:%s/user/account_check", config.LoadConfig().APIHost, config.LoadConfig().APIPort)
@@ -70,7 +70,7 @@ func GetUsers(token string, pageNumber, showNumber int) error {
return sendPostRequestWithToken(url, token, requestBody)
}
// sendPostRequestWithToken sends a POST request with a token in the header
// sendPostRequestWithToken sends a POST request with a token in the header.
func sendPostRequestWithToken(url, token string, body any) error {
reqBytes, err := json.Marshal(body)
if err != nil {