### MySQL Database Configuration Source: https://context7.com/babyname/fate/llms.txt Programmatic setup for MySQL database connection within the Go application. ```go cfg := config.DefaultConfig() cfg.Database = config.Database{ Host: "127.0.0.1", Port: "3306", User: "root", Pwd: "your_password", Name: "fate", MaxIdleCon: 10, MaxOpenCon: 100, Driver: "mysql", ShowSQL: false, ShowExecTime: false, } ``` -------------------------------- ### Configuration File Structure Source: https://context7.com/babyname/fate/llms.txt Example of the JSON configuration file used for customizing name generation parameters and database settings. ```json { "run_init": false, "filter_mode": 0, "stroke_max": 18, "stroke_min": 3, "hard_filter": true, "fix_bazi": false, "supply_filter": true, "zodiac_filter": true, "bagua_filter": true, "regular": true, "database": { "host": "127.0.0.1", "port": "3306", "user": "root", "pwd": "password", "name": "fate", "driver": "mysql" }, "file_output": { "output_mode": 0, "path": "names.txt", "heads": ["姓名", "笔画", "拼音", "喜用神", "八字"] } } ``` -------------------------------- ### Initialize and Generate Name with Binary Source: https://github.com/babyname/fate/blob/main/README.md These shell commands demonstrate how to use the pre-compiled binary to initialize the application and generate names. The `init` command sets up the configuration, and the `name` command generates a name based on the provided last name and birth date. ```shell #生成配置文件, 可修改数据库, 及一些基本参数 fate.exe init #输出姓名 fate.exe name -l 张 -b "2020/02/06 15:04" ``` -------------------------------- ### Configure SQLite3 Database Source: https://context7.com/babyname/fate/llms.txt Set up the default configuration to use an SQLite3 database named 'fate'. This configures the database file and driver. ```go cfg := config.DefaultConfig() cfg.Database = config.Database{ Name: "fate", // Database file: fate.db Driver: "sqlite3", } ``` -------------------------------- ### Create Fate Instance with Custom Config Source: https://context7.com/babyname/fate/llms.txt Initializes a Fate instance with a custom configuration, allowing fine-tuning of name generation parameters. Supports filters, stroke limits, and database/output settings. ```go package main import ( "context" "github.com/babyname/fate" "github.com/babyname/fate/config" "github.com/godcong/chronos" ) func main() { born := chronos.New("2024/08/08 08:08") lastName := "王" // Create custom configuration // 创建自定义配置 cfg := &config.Config{ // Minimum stroke count for given name characters // 名字字符最小笔画数 StrokeMin: 3, // Maximum stroke count for given name characters // 名字字符最大笔画数 StrokeMax: 18, // Enable hard filter (stricter luck requirements) // 启用严格过滤(更严格的吉凶要求) HardFilter: true, // Enable BaZi supply filter (喜用神过滤) // 启用八字喜用神过滤 SupplyFilter: true, // Enable zodiac-based character filter // 启用生肖用字过滤 ZodiacFilter: true, // Enable Zhou Yi Bagua filter // 启用周易八卦过滤 BaguaFilter: true, // Use only commonly used characters // 仅使用常用字 Regular: true, // Database configuration (SQLite3) // 数据库配置(SQLite3) Database: config.Database{ Name: "fate", Driver: "sqlite3", }, // Output configuration // 输出配置 FileOutput: config.FileOutput{ OutputMode: config.OutputModeLog, // Log format output Path: "generated_names.txt", Heads: []string{"姓名", "笔画", "拼音", "喜用神", "八字"}, }, } f := fate.NewFate(lastName, born.Solar().Time(), fate.ConfigOption(cfg)) err := f.MakeName(context.Background()) if err != nil { panic(err) } } ``` -------------------------------- ### Access Name Attributes Source: https://context7.com/babyname/fate/llms.txt Demonstrates how to generate names and access their properties like strokes, pinyin, WuXing, and BaZi using a registered handler. ```go package main import ( "context" "fmt" "github.com/babyname/fate" "github.com/babyname/fate/config" "github.com/godcong/chronos" ) func main() { born := chronos.New("2024/03/15 14:30") lastName := "张" cfg := config.DefaultConfig() cfg.StrokeMax = 10 cfg.StrokeMin = 5 f := fate.NewFate(lastName, born.Solar().Time(), fate.ConfigOption(cfg)) // Register a handler to process each generated name // 注册处理器来处理每个生成的姓名 f.RegisterHandle(func(name fate.Name) { // Get full name string // 获取完整姓名字符串 fullName := name.String() fmt.Printf("姓名: %s\n", fullName) // Get stroke counts // 获取笔画数 strokes := name.Strokes() fmt.Printf("笔画: %s\n", strokes) // Get pinyin // 获取拼音 pinyin := name.PinYin() fmt.Printf("拼音: %s\n", pinyin) // Get WuXing attributes // 获取五行属性 wuxing := name.WuXing() fmt.Printf("五行: %s\n", wuxing) // Get XiYong Shen (favorable element) // 获取喜用神 xiYong := name.XiYongShen() fmt.Printf("喜用神: %s\n", xiYong) // Get BaZi string // 获取八字字符串 bazi := name.BaZi() fmt.Printf("八字: %s\n", bazi) fmt.Println("---") }) err := f.MakeName(context.Background()) if err != nil { panic(err) } // Example output for one name: // 姓名: 张明轩 // 笔画: 11,8,10 // 拼音: [zhāng][míng][xuān] // 五行: 火火土 // 喜用神: 水 // 八字: 甲辰丁卯壬午辛巳 } ``` -------------------------------- ### CLI Name Generation Source: https://context7.com/babyname/fate/llms.txt Commands for initializing configuration and generating names via the command line. ```bash # Initialize configuration file (creates config.json) # 初始化配置文件(创建 config.json) fate init # Generate names with surname and birth date # 使用姓氏和出生日期生成姓名 fate name -l 张 -b "2024/03/15 14:30" # Generate names for a girl # 为女孩生成姓名 fate name -l 李 -b "2024/06/20 10:15" -s true # Specify custom config path # 指定自定义配置路径 fate name -l 王 -b "2024/08/08 08:08" -p /path/to/config # Specify output path # 指定输出路径 fate name -l 陈 -b "2024/05/10 16:20" -o /path/to/output ``` -------------------------------- ### Importing SQL Database Source: https://github.com/babyname/fate/blob/main/README.md Instructions for importing a SQL database file into MySQL. This involves connecting to the MySQL server, creating the `fate` schema, and then sourcing the SQL file. Using a tool like Navicat is recommended for faster import. ```sql //链接到mysql数据库 mysql -u用户名 -p密码 //创建数据库 CREATE schema `fate` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin; //使用fate数据库 use fate; //导入数据库文件 source /path/to/sql/file; PS:建议使用Navicat等工具导入,导入速度较快 ``` -------------------------------- ### Create Fate Instance with Default Config Source: https://context7.com/babyname/fate/llms.txt Initializes a new Fate instance for name generation using default configuration. Requires surname and birth time. Supports single or double surnames. ```go package main import ( "context" "time" "github.com/babyname/fate" "github.com/babyname/fate/config" "github.com/godcong/chronos" ) func main() { // Set birth date using chronos library // 设置出生日期 born := chronos.New("2024/03/15 14:30") // Set surname (supports single or double surnames) // 设置姓氏(支持单姓或复姓) lastName := "张" // Create Fate instance with default config // 使用默认配置创建 Fate 实例 f := fate.NewFate(lastName, born.Solar().Time()) // Generate names // 生成姓名 err := f.MakeName(context.Background()) if err != nil { panic(err) } } ``` -------------------------------- ### Generate Names with Default Config Source: https://context7.com/babyname/fate/llms.txt Generates names using the MakeName method with a default configuration. The generated names are written to a default file (name.txt). Handles potential errors during generation. ```go package main import ( "context" "fmt" "time" "github.com/babyname/fate" "github.com/babyname/fate/config" "github.com/godcong/chronos" ) func main() { born := chronos.New("2024/06/20 10:15") lastName := "李" cfg := config.DefaultConfig() f := fate.NewFate(lastName, born.Solar().Time(), fate.ConfigOption(cfg)) // MakeName generates names and writes to configured output // MakeName 生成姓名并写入配置的输出 err := f.MakeName(context.Background()) if err != nil { fmt.Printf("Name generation failed: %v\n", err) return } fmt.Println("Name generation completed successfully") // Output: Names written to configured file (default: name.txt) } ``` -------------------------------- ### Create BaZi Analysis Object Source: https://context7.com/babyname/fate/llms.txt Creates a BaZi analysis object from a birth calendar to calculate favorable elements. ```go package main import ( "fmt" "github.com/babyname/fate" "github.com/godcong/chronos" ) func main() { // Create calendar from birth date // 从出生日期创建日历对象 born := chronos.New("2024/07/15 09:30") // Create BaZi instance // 创建八字实例 bazi := fate.NewBazi(born) // Get the complete BaZi string // 获取完整的八字字符串 fmt.Printf("八字: %s\n", bazi.String()) // Output example: 八字: 甲辰己未壬午乙巳 // Get the Day Master (日主) // 获取日主 riZhu := bazi.RiZhu() fmt.Printf("日主: %s\n", riZhu) // Output example: 日主: 壬 // Get favorable element // 获取喜用神 xiYongShen := bazi.XiYongShen() fmt.Printf("喜用神: %s\n", xiYongShen) // Output example: 喜用神: 金 } ``` -------------------------------- ### SQLite3 Database Configuration Source: https://github.com/babyname/fate/blob/main/README.md Configure the `database` section in `config.json` for SQLite3. Provide the database name, which should be placed in the same directory as the `fate` executable. The `driver` must be set to `sqlite3`. ```json "database": { "name": "fate", "driver": "sqlite3", }, ``` -------------------------------- ### NewFate - Initialize Name Generator Source: https://context7.com/babyname/fate/llms.txt Initializes a new Fate instance with a surname and birth date to prepare for name generation. ```APIDOC ## NewFate ### Description Creates a new Fate instance for name generation. This is the main entry point for the library. ### Parameters - **lastName** (string) - Required - The surname (supports single or double surnames). - **born** (time.Time) - Required - The birth date and time. ### Request Example ```go f := fate.NewFate(lastName, born.Solar().Time()) ``` ``` -------------------------------- ### MySQL Database Configuration Source: https://github.com/babyname/fate/blob/main/README.md Configure the `database` section in `config.json` for MySQL. Specify the host, port, user, password, and database name. Ensure the `driver` is set to `mysql`. ```json "database": { "host": "127.0.0.1", "port": "3306", "user": "root", "pwd": "111111", "name": "fate", "max_idle_con": 0, "max_open_con": 0, "driver": "mysql", "file": "", "dsn": "", "show_sql": false, "show_exec_time": false }, ``` -------------------------------- ### Create SanCai Object Source: https://context7.com/babyname/fate/llms.txt Initializes a SanCai object to analyze Heaven, Human, and Earth elements. Requires a database connection to verify luck thresholds. ```go package main import ( "github.com/babyname/fate" "github.com/xormsharp/xorm" _ "github.com/mattn/go-sqlite3" ) func main() { // Calculate SanCai from TianGe, RenGe, DiGe values // 从天格、人格、地格值计算三才 tianGe := 12 renGe := 19 diGe := 18 sanCai := fate.NewSanCai(tianGe, renGe, diGe) // To check SanCai luck, you need a database connection // 检查三才吉凶需要数据库连接 engine, err := xorm.NewEngine("sqlite3", "./fate.db") if err != nil { panic(err) } // Check if SanCai passes minimum luck threshold (5 points) // 检查三才是否通过最低吉祥阈值(5分) isGood := fate.Check(engine, sanCai, 5) if isGood { println("三才配置良好") } else { println("三才配置不佳") } } ``` -------------------------------- ### Generate Name with Go Code Source: https://github.com/babyname/fate/blob/main/README.md Use this Go code snippet to programmatically generate names. Ensure you have loaded the necessary database and configured the settings. The `fate.NewFate` function takes the last name and birth time, with `fate.ConfigOption` for custom configurations. ```go cfg := config.Default() // 生日: born := chronos.New("2020/01/23 11:31") // 姓氏: lastName := "张" // 第一参数:姓氏 // 第二参数:生日 f := fate.NewFate(lastName, born.Solar().Time(), fate.ConfigOption(cfg)) e := f.MakeName(context.Background()) if e != nil { t.Fatal(e) } ``` -------------------------------- ### Retrieve XiYong (Favorable Element) Source: https://context7.com/babyname/fate/llms.txt Calculates the XiYong (喜用神) based on the birth date's BaZi to determine favorable WuXing elements. ```go package main import ( "fmt" "github.com/babyname/fate" "github.com/babyname/fate/config" "github.com/godcong/chronos" ) func main() { born := chronos.New("2024/03/15 14:30") lastName := "张" cfg := config.DefaultConfig() f := fate.NewFate(lastName, born.Solar().Time(), fate.ConfigOption(cfg)) // Get XiYong (喜用神) information // 获取喜用神信息 xiYong := f.XiYong() // Get the recommended element (喜用神) // 获取推荐的五行元素 shen := xiYong.Shen() fmt.Printf("喜用神 (Favorable Element): %s\n", shen) // Output example: 喜用神 (Favorable Element): 水 // Check if BaZi is strong or weak // 检查八字偏强还是偏弱 if xiYong.QiangRuo() { fmt.Println("八字偏强 (BaZi is strong)") } else { fmt.Println("八字偏弱 (BaZi is weak)") } } ``` -------------------------------- ### ConfigOption - Configure Generation Source: https://context7.com/babyname/fate/llms.txt Defines the configuration parameters for name generation, including filters and database settings. ```APIDOC ## ConfigOption ### Description Provides configuration options for name generation including filters, stroke limits, database settings, and output format. ### Configuration Fields - **StrokeMin** (int) - Optional - Minimum stroke count for given name characters. - **StrokeMax** (int) - Optional - Maximum stroke count for given name characters. - **HardFilter** (bool) - Optional - Enable stricter luck requirements. - **SupplyFilter** (bool) - Optional - Enable BaZi supply filter (喜用神). - **ZodiacFilter** (bool) - Optional - Enable zodiac-based character filter. - **BaguaFilter** (bool) - Optional - Enable Zhou Yi Bagua filter. - **Regular** (bool) - Optional - Use only commonly used characters. - **Database** (object) - Optional - Database configuration (Driver and Name). - **FileOutput** (object) - Optional - Output configuration (Path, Mode, and Headers). ``` -------------------------------- ### MakeName - Generate Names Source: https://context7.com/babyname/fate/llms.txt Executes the name generation process based on configured criteria and filters. ```APIDOC ## MakeName ### Description The main method that generates names based on the configured criteria. It processes all WuGe combinations and applies filters. ### Parameters - **ctx** (context.Context) - Required - Context for the operation. ### Response - **error** (error) - Returns nil on success, or an error if generation fails. ``` -------------------------------- ### Configure Gender Filter Source: https://context7.com/babyname/fate/llms.txt Configures the gender filter to exclude numbers traditionally considered unsuitable for females. ```go package main import ( "context" "github.com/babyname/fate" "github.com/babyname/fate/config" "github.com/godcong/chronos" ) func main() { born := chronos.New("2024/05/10 16:20") lastName := "陈" cfg := config.DefaultConfig() // Set sex option: fate.SexBoy (false) or fate.SexGirl (true) // 设置性别选项:fate.SexBoy (男) 或 fate.SexGirl (女) f := fate.NewFate( lastName, born.Solar().Time(), fate.ConfigOption(cfg), fate.SexOption(fate.SexGirl), // Filter out numbers unsuitable for females ) err := f.MakeName(context.Background()) if err != nil { panic(err) } } ``` -------------------------------- ### Calculate Five-Grid Numerology Source: https://context7.com/babyname/fate/llms.txt Calculates the Five-Grid (WuGe) numerology based on character stroke counts. ```go package main import ( "fmt" "github.com/babyname/fate" ) func main() { // Stroke counts: LastName1, LastName2, FirstName1, FirstName2 // 笔画数:姓1, 姓2, 名1, 名2 // For single surname, LastName2 = 0 // 单姓时,LastName2 = 0 // Example: 张 (11 strokes) + 明 (8) + 轩 (10) // 示例:张(11画)+ 明(8画)+ 轩(10画) l1 := 11 // 张 l2 := 0 // Single surname (单姓) f1 := 8 // 明 f2 := 10 // 轩 wuge := fate.CalcWuGe(l1, l2, f1, f2) fmt.Printf("天格 (TianGe): %d\n", wuge.TianGe()) fmt.Printf("人格 (RenGe): %d\n", wuge.RenGe()) fmt.Printf("地格 (DiGe): %d\n", wuge.DiGe()) fmt.Printf("外格 (WaiGe): %d\n", wuge.WaiGe()) fmt.Printf("总格 (ZongGe): %d\n", wuge.ZongGe()) // Check if WuGe is auspicious // 检查五格是否吉利 isLucky := wuge.Check("吉", "半吉") fmt.Printf("五格吉凶: %v\n", isLucky) // Output: // 天格 (TianGe): 12 // 人格 (RenGe): 19 // 地格 (DiGe): 18 // 外格 (WaiGe): 11 // 总格 (ZongGe): 29 // 五格吉凶: false } ``` -------------------------------- ### Retrieve Zodiac Information Source: https://context7.com/babyname/fate/llms.txt Fetches zodiac details based on a birth date, including favorable (Xi) and unfavorable (Ji) characters. ```go package main import ( "fmt" "github.com/babyname/fate" "github.com/godcong/chronos" ) func main() { // Create calendar for birth date // 创建出生日期的日历 born := chronos.New("2024/03/15 14:30") // Year of the Dragon (龙年) // Get zodiac information // 获取生肖信息 zodiac := fate.GetZodiac(born) if zodiac != nil { fmt.Printf("生肖: %s\n", zodiac.Name) // Output: 生肖: 龙 // Zodiac has Xi (喜/favorable) and Ji (忌/unfavorable) characters // 生肖有喜用字和忌用字 fmt.Printf("忌用字数量: %d\n", len([]rune(zodiac.Ji))) } } ``` -------------------------------- ### Retrieve DaYan Interpretation Source: https://context7.com/babyname/fate/llms.txt Retrieves the DaYan interpretation for a given number (1-81), including luck status and gender suitability. ```go package main import ( "fmt" "github.com/babyname/fate" ) func main() { // Get DaYan interpretation for number 21 // 获取数字21的大衍解释 dayan := fate.GetDaYan(21) fmt.Printf("数字 (Number): %d\n", dayan.Number) fmt.Printf("吉凶 (Lucky): %s\n", dayan.Lucky) fmt.Printf("名称 (SkyNine): %s\n", dayan.SkyNine) fmt.Printf("解释 (Comment): %s\n", dayan.Comment) fmt.Printf("女性不宜 (Not suitable for female): %v\n", dayan.IsNotSuitableSex()) // Output: // 数字 (Number): 21 // 吉凶 (Lucky): 吉 // 名称 (SkyNine): 明月中天 // 解释 (Comment): 光风霁月,万物确立,官运亨通,大搏名利。女性不宜此数。 // 女性不宜 (Not suitable for female): true // Check for maximum luck number (41) // 检查最大好运数(41) maxLucky := fate.GetDaYan(41) fmt.Printf("\n41 是否最大好运数: %v\n", maxLucky.IsMax()) // Output: 41 是否最大好运数: true } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.