/gemini

a microservice core component

Primary LanguageGoMIT LicenseMIT

Go Report Card GitHub

gemini

Introduction

GEMINI is a microservice framework

Quick Start

package main

import (
    _ "demo/schedule"
    _ "demo/task"
    
    
    "os"
    "demo/services"

    "github.com/Jarnpher553/gemini/config"
    "github.com/Jarnpher553/gemini/redis"
    "github.com/Jarnpher553/gemini/repo"
    "github.com/Jarnpher553/gemini/router"
    "github.com/Jarnpher553/gemini/scheduler"
    "github.com/Jarnpher553/gemini/server"
    "github.com/Jarnpher553/gemini/service"
    "github.com/Jarnpher553/gemini/task"
    "github.com/Jarnpher553/gemini/task/delay"
)

func main() {
    env := config.DeployEnv(os.Args)
    
    // 获取对应项的配置
    serverCf := config.Conf().Sub("server")
    mysqlCf := config.Conf().Sub("mysql")
    redisCf := config.Conf().Sub("redis")
    
    // 数据库实例
    db := repo.New(repo.DbName(mysqlCf.GetString("dbName")), repo.Addr(mysqlCf.GetString("addr")), repo.Pwd(mysqlCf.GetString("password")), repo.UserName(mysqlCf.GetString("username")), repo.LogMode(false))
    rd := redis.New(redis.Pwd(redisCf.GetString("password")), redis.PoolSize(redisCf.GetInt("poolSize")), redis.DB(redisCf.GetInt("db")), redis.Addr(redisCf.GetString("addr")))
    
    
    // 实例化服务
    userService := service.NewService(&services.UserService{}, service.Repository(db), service.RedisClient(rd))
    
    scheduler.Bind(scheduler.Repo(db), scheduler.Redis(rd))
    delay.Bind(true, task.Redis(rd), task.Repo(db))
    
    // 实例化路由
    r := router.New()
    // 将服务注册进路由
    r.Assign(userService)
    
    // 实例化服务器
    srv := server.Default(server.Name("demo"), server.Env(env), server.RunMode(serverCf.GetString("runMode")), server.Router(r), server.Addr(serverCf.GetString("addr")))
    
    // 运行服务器
    srv.Run()
}