### MySQL Connection String Example Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Provides a concrete example of a MySQL connection string with sample credentials and database name. ```sql root:test123@tcp(127.0.0.1:3306)/wow_hong?charset=utf8&parseTime=True&loc=Local ``` -------------------------------- ### GET /macro60/ Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Loads the home page for the legacy macro tool. ```APIDOC ## GET /macro60/ ### Description Load legacy macro tool home page. ### Method GET ### Endpoint /macro60/ ``` -------------------------------- ### Search API Example Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/START-HERE.txt Shows how to search for APIs using a GET request to the /api/search endpoint. The search keyword must be longer than 3 characters. ```http GET /api/search?s=GetTime ``` -------------------------------- ### GET /macro60/preCreate Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Searches for shared legacy macros. Query parameters and response schema are the same as `/macro/preCreate`. ```APIDOC ## GET /macro60/preCreate ### Description Search shared legacy macros. ### Method GET ### Endpoint /macro60/preCreate ### Query Parameters Same as `/macro/preCreate` ### Response Schema Same as `/macro/preCreate` (returns MacrosOld60 objects) ``` -------------------------------- ### View Analytics Data Example Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/START-HERE.txt Demonstrates how to retrieve analytics data using a GET request to the /chart/data endpoint, specifying start and end dates. Authentication is required via a 'token' cookie. ```http GET /chart/data?sd=2026-06-01&ed=2026-06-30 Cookie: token=testcode ``` -------------------------------- ### Create Macro Example Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/START-HERE.txt Demonstrates the JSON payload required to create a new macro via the POST /macro/ endpoint. Ensure the Content-Type header is set to application/json. ```json { "title": "My Macro", "macro": "/cast spell", "author": "MyName" } ``` -------------------------------- ### SQL Query Logging Example Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Shows the format of logged SQL queries when debug level logging is enabled. This helps in diagnosing database performance issues. ```text [2026-01-15 10:30:45] SELECT * FROM macros WHERE is_verify = ? [1] ``` -------------------------------- ### GET /macro/preCreate Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Searches for shared macros based on a provided keyword to assist in macro creation. Returns a list of matching macros. ```APIDOC ## GET /macro/preCreate ### Description Searches shared macros to assist macro creation. ### Method GET ### Endpoint /macro/preCreate ### Parameters #### Query Parameters - **macro** (string) - Required - Macro name/keyword to search ### Response #### Success Response (0) - **code** (integer) - 0 for success - **data** (array) - List of matching macros, each with id, title, macro, author, updatetime, isVerify, masteryId, professionId. #### Response Example (Success) ```json { "code": 0, "data": [ { "id": 1, "title": "Healing Macro", "macro": "/cast [@target,help] Healing Touch", "author": "Healer", "updatetime": "2026-01-15T10:30:00Z", "isVerify": 1, "masteryId": 1, "professionId": 2 } ] } ``` #### Error Response (500) - **code** (integer) - 500 for error - **msg** (string) - Error message #### Response Example (Error) ```json { "code": 500, "msg": "params is empty" } ``` #### Status Codes | Code | Meaning | |------|---------| | 0 | Success | | 500 | Missing parameters or database error | ``` -------------------------------- ### GET /macro/ Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Loads the macro tool home page. This endpoint is intended for user interface display and logs page views. ```APIDOC ## GET /macro/ ### Description Loads the macro tool home page. ### Method GET ### Endpoint /macro/ ### Response HTML page (macro_home.html) ``` -------------------------------- ### GET /macro60/macroList Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Retrieves a paginated list of legacy macros. Query parameters and response schema are the same as `/macro/macroList`. ```APIDOC ## GET /macro60/macroList ### Description Get paginated legacy macro list. ### Method GET ### Endpoint /macro60/macroList ### Query Parameters Same as `/macro/macroList` ### Response Schema Same as `/macro/macroList` (SimpleMacro60 objects) ``` -------------------------------- ### Making Database Connection Configurable Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Modify the database connection string to use configurable host and port instead of hardcoded values. This example shows the current hardcoded approach and the proposed change. ```go // Current (hardcoded): DbConn, err = gorm.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/%s?charset=utf8...", global.Config.DbUser, global.Config.DbPwd, global.Config.DbName)) // To make configurable: DbConn, err = gorm.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8...", global.Config.DbUser, global.Config.DbPwd, global.Config.DbHost, global.Config.DbPort, global.Config.DbName)) ``` -------------------------------- ### GET / Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Serves the main index page of the application. This route is intended for general access and logs page views. ```APIDOC ## GET / ### Description Main index page. ### Method GET ### Endpoint / ### Response #### Success Response (200) - **Response**: HTML page (index.html) ``` -------------------------------- ### Example Cookie Header for Authentication Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Demonstrates the format for the HTTP Cookie header used for authentication. The 'token' cookie is required for specific endpoints. ```http Cookie: token=testcode ``` -------------------------------- ### Generate Cast Sequence Example Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/START-HERE.txt Illustrates the JSON array format for generating a spell cast sequence via the POST /macro/createSequence endpoint. Each object specifies skill name, level, and cooldown. ```json [ {"skillName": "Spell1", "level": 1, "cooldown": 300}, {"skillName": "Spell2", "level": 2, "cooldown": 200} ] ``` -------------------------------- ### GET /macro60/view/:name Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Loads a specific legacy macro view based on the provided name. Requires token authentication for the 'verify' name. ```APIDOC ## GET /macro60/view/:name ### Description Load specific legacy macro view. ### Method GET ### Endpoint /macro60/view/:name ### Parameters #### Path Parameters - **name** (string) - Required - The name of the macro view to load. ``` -------------------------------- ### Initialize API Data and Fetch Details Source: https://github.com/illidan33/wow_api/blob/master/public/html/wow_api/api_head_script.html This script initializes API data and defines a function to fetch and display API details. It uses jQuery to make an AJAX GET request to '/api/list' and populates a table with the results. Ensure jQuery is loaded before this script. ```javascript var api = {{.apiPage}}; function apiDetail(pid, api) { $.get("/api/list", {pid: pid, type: api}, function(data) { if (data) { var text = ''; $.each(data.list, function(k, v) { text += ' ' + v.name + ' ' + v.desc + ''; }); $("#api-list").html(text); } }, "json"); } ``` -------------------------------- ### GET * (NoRoute) Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md A catch-all route that handles any unmatched URLs by directing them to the main index page. This is useful for single-page applications. ```APIDOC ## GET * (NoRoute) ### Description Catch-all for unmatched routes. ### Method GET ### Endpoint * ### Response #### Success Response (200) - **Response**: HTML page (index.html) ### Note Routes all unmatched URLs to the main index. ``` -------------------------------- ### GET /macro/view/:name Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Loads a specific macro view page based on the provided name. It handles special cases like verification and requires a valid token for certain views. ```APIDOC ## GET /macro/view/:name ### Description Loads a specific macro view page. ### Method GET ### Endpoint /macro/view/:name ### Parameters #### Path Parameters - **name** (string) - Required - View name (e.g., "create", "verify") ### Special Handling - If `name` is "verify", requires valid token cookie matching `VerifyCode`. - Returns 401 if verification required but token invalid. ### Response HTML page (macro_{name}.html) ``` -------------------------------- ### GET /chart/data Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Retrieves visitor statistics for a specified date range. Supports optional start and end dates for filtering. ```APIDOC ## GET /chart/data ### Description Get visitor statistics for a date range. ### Method GET ### Endpoint /chart/data ### Parameters #### Query Parameters - **sd** (string) - Optional - Start date (YYYY-MM-DD). Defaults to 20 days ago. - **ed** (string) - Optional - End date (YYYY-MM-DD). Defaults to Today. ### Response #### Success Response (0) - **code** (integer) - Success code. - **data** (array) - Array of statistics objects, each containing 'name' and 'data' arrays. - **title** (array) - Array of date strings for the chart. ### Response Example ```json { "code": 0, "data": [ { "name": "IP", "data": [100, 150, 120, ...] }, { "name": "Page/10", "data": [50, 60, 55, ...] }, { "name": "Api/10", "data": [75, 85, 70, ...] } ], "title": ["2026-06-13", "2026-06-14", ...] } ``` #### Error Response (500) - **Meaning**: Database error. ``` -------------------------------- ### Production Environment Configuration Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Set up production configuration with appropriate host, port, logging level, and file paths. Use secure tokens and database credentials for production. ```go global.Config.ListenHost = "0.0.0.0" global.Config.ListenPort = 8002 global.Config.LogLevel = logrus.InfoLevel global.Config.IsSaveLog = true global.Config.LogPath = "/var/log/wow_api/app.log" global.Config.VerifyCode = "secure_production_token" global.Config.DbUser = "wow_api" global.Config.DbPwd = "production_db_password" global.Config.DbName = "wow_production" ``` -------------------------------- ### Logging in Application Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Demonstrates various ways to use the global logger instance for different logging levels and structured logging. ```go // Debug logging global.Log.Debugf("Request: %+v", request) // Info logging global.Log.Info("Server started") // Error logging global.Log.Error(err) // Structured logging global.Log.WithField("ip", clientIP).Info("User accessed") ``` -------------------------------- ### Development Environment Configuration Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Configure settings for local development, including host, port, logging level, and log file path. Use a development-specific token for verification. ```go global.Config.ListenHost = "localhost" global.Config.ListenPort = 8080 global.Config.LogLevel = logrus.DebugLevel global.Config.IsSaveLog = true global.Config.LogPath = "./logs/dev.log" global.Config.VerifyCode = "dev_token" global.Config.ChartDay = 30 ``` -------------------------------- ### Access Server Configuration Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Read configuration values from the global singleton. Ensure the 'global' package is imported. ```go import "github.com/illidan33/wow_api/global" // Read configuration host := global.Config.ListenHost port := global.Config.ListenPort token := global.Config.VerifyCode ``` -------------------------------- ### Global Configuration Usage Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/04-core-modules.md Demonstrates how to access configuration values and conditionally set the Gin mode based on the log level. Ensure necessary imports are included. ```go import "github.com/illidan33/wow_api/global" host := global.Config.ListenHost port := global.Config.ListenPort token := global.Config.VerifyCode if global.Config.LogLevel != logrus.DebugLevel { gin.SetMode(gin.ReleaseMode) } ``` -------------------------------- ### Modify Server Configuration at Runtime Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Update configuration values before server startup. Changes to global.Config are effective immediately. ```go global.Config.ListenPort = 8080 global.Config.DbHost = "db.example.com" global.Config.VerifyCode = "custom_token" ``` -------------------------------- ### Get Chart Data Error Response - JSON Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md The JSON structure for an error response from the GetChartData handler, indicating a server-side issue. ```json { "code": 500 } ``` -------------------------------- ### GET /macro/professionList Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Retrieves a list of professions that can be used for filtering macros. Supports filtering by game version and parent profession ID. ```APIDOC ## GET /macro/professionList ### Description Gets profession list for macro filtering. ### Method GET ### Endpoint /macro/professionList ### Parameters #### Query Parameters - **v** (string) - Optional - Game version - Default: 0 - **pid** (string) - Optional - Parent profession ID - Default: 0 ### Response #### Success Response (0) - **code** (integer) - 0 for success - **data** (array) - List of professions, each with id and name. #### Response Example (Success) ```json { "code": 0, "data": [ { "id": 1, "name": "Warrior" }, { "id": 2, "name": "Paladin" } ] } ``` #### Status Codes | Code | Meaning | |------|---------| | 0 | Success | | 500 | Invalid filters or database error | ``` -------------------------------- ### Initialize MySQL Database Connection Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/04-core-modules.md Initializes a global GORM database connection using MySQL. Panics on failure. Ensure the connection string format is correct and host/port are accessible. ```go import ( "github.com/go-sql-driver/mysql" "github.com/illidan33/wow_api/modules" "gorm.io/gorm" "gorm.io/gorm/logger" ) var DbConn *gorm.DB func init() { connArgs := mysql.Config{ User: "user", Passwd: "password", Net: "tcp", Addr: "127.0.0.1:3306", DBName: "database", Collation: "utf8_general_ci", Params: map[string]string{ "charset": "utf8mb4", "parseTime": "True", "loc": "Local", }, } dialector := mysql.New(mysql.Config{ DSN: connArgs.FormatDSN(), DefaultStringSize: 256, // Default length for string types }) var err error DbConn, err = gorm.Open(dialector, &gorm.Config{ Logger: logger.Default.LogMode(logger.Info), NamingStrategy: schema.NamingStrategy{ SingularTable: true, }, }) if err != nil { panic("failed to connect database") } sqlDB, _ := DbConn.DB() if sqlDB.Ping() != nil { panic("failed to ping database") } } ``` -------------------------------- ### POST /macro60/ Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Creates and shares a legacy macro. Request body and response schema are the same as `/macro/`. ```APIDOC ## POST /macro60/ ### Description Create and share a legacy macro. ### Method POST ### Endpoint /macro60/ ### Request Body Same as `/macro/` (JSON with title, macro, author fields) ### Response Schema Same as `/macro/` ``` -------------------------------- ### GET /macro/view Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Loads the general macro page without a specific view. This endpoint is for UI display and logs page views. ```APIDOC ## GET /macro/view ### Description Loads the macro page (no specific view). ### Method GET ### Endpoint /macro/view ### Response HTML page (macro_home.html) ``` -------------------------------- ### Global Configuration Struct Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/04-core-modules.md Defines the application-wide settings, including server host/port, database credentials, and logging preferences. Access configuration values directly from the `global.Config` singleton. ```go var Config = struct { ListenHost string ListenPort int32 ApiRootPath string DbHost string DbPort int32 DbUser string DbPwd string DbName string IsSaveLog bool LogPath string LogLevel logrus.Level VerifyCode string ChartDay int64 }{ ListenHost: "127.0.0.1", ListenPort: 8002, DbHost: "127.0.0.1", DbPort: 3306, DbUser: "root", DbPwd: "test123", DbName: "wow_hong", IsSaveLog: true, LogPath: "./logs/log.txt", LogLevel: logrus.DebugLevel, VerifyCode: "testcode", ChartDay: 20, } ``` -------------------------------- ### GET /chart/ Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Displays the chart analytics dashboard page. Access to this route requires authentication via a valid token cookie. ```APIDOC ## GET /chart/ ### Description Chart analytics dashboard page. ### Method GET ### Endpoint /chart/ ### Authentication Required (token cookie) ### Response #### Success Response (200) - **Response**: HTML page (chart.html) ``` -------------------------------- ### Recommended Production Configuration Changes Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Update these fields to enhance security and set appropriate logging levels for production. Ensure strong, random passwords and secure tokens. ```go global.Config.DbUser = "app_user" global.Config.DbPwd = "strong_random_password" global.Config.VerifyCode = "cryptographically_secure_token" global.Config.LogLevel = logrus.WarnLevel global.Config.ListenHost = "0.0.0.0" ``` -------------------------------- ### Index Handler - Go Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Renders the main landing page and logs page views. This handler serves as the application's entry point. ```go func Index(c *gin.Context) { // Logs access: CreateLoginLog(c, "index.html", 1) // Renders HTML template: index.html // Passes data: {"apiPage": "home"} } ``` -------------------------------- ### Index() Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Renders the main landing page and logs page views. It serves as the application's entry point. ```APIDOC ## GET / ### Description Renders the main landing page and logs page views. This handler is the entry point for the application. ### Method GET ### Endpoint / ### Behavior 1. Logs access: `CreateLoginLog(c, "index.html", 1)` 2. Renders HTML template: `index.html` 3. Passes data: `{"apiPage": "home"}` ### Returns HTML response (HTTP 200) ``` -------------------------------- ### Create and Share WoW Macro Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md This endpoint allows users to create and share new WoW macros. It requires a title, the macro commands, and the author's name. Optional fields include mastery and profession IDs. The response indicates success or failure. ```json { "title": "My Healing Macro", "macro": "/cast [@target,help] Healing Touch", "author": "Healer", "masteryId": 1, "professionId": 2 } ``` ```json { "code": 0, "data": "ok" } ``` ```json { "code": 500, "msg": "params is error" } ``` -------------------------------- ### GET /macro/macroList Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Retrieves a paginated list of macros with options for filtering by ID, verification status, profession, mastery, and version. Supports returning simplified or full macro objects. ```APIDOC ## GET /macro/macroList ### Description Gets paginated list of macros with filtering. ### Method GET ### Endpoint /macro/macroList ### Parameters #### Query Parameters - **id** (string) - Optional - Macro ID (exact match) - **isVerify** (string) - Optional - Verification status (1=verified, 2=unverified) - Default: 1 - **professionId** (string) - Optional - Filter by profession (0=all) - Default: 0 - **masteryId** (string) - Optional - Filter by mastery (0=all) - Default: 0 - **pageNo** (string) - Optional - Page number (1-indexed) - Default: 1 - **pageSize** (string) - Optional - Results per page (-1 for all) - Default: 10 - **v** (string) - Optional - Special flag; "v" returns full macro objects instead of simplified - Default: "" ### Response #### Success Response (0) (with v!=v) - **code** (integer) - 0 for success - **pageNo** (integer) - Current page number - **data** (array) - List of simplified macro objects, each with title, macro, author. #### Response Example (Success, v!=v) ```json { "code": 0, "pageNo": 1, "data": [ { "title": "Macro Name", "macro": "/cast spell", "author": "Author" } ] } ``` #### Success Response (0) (with v=v) - **code** (integer) - 0 for success - **pageNo** (integer) - Current page number - **data** (array) - List of full macro objects, each with id, title, macro, author, updatetime, isVerify, masteryId, professionId. #### Response Example (Success, v=v) ```json { "code": 0, "pageNo": 1, "data": [ { "id": 1, "title": "Macro Name", "macro": "/cast spell", "author": "Author", "updatetime": "2026-01-15T10:30:00Z", "isVerify": 1, "masteryId": 1, "professionId": 2 } ] } ``` #### Status Codes | Code | Meaning | |------|---------| | 0 | Success | | 500 | Invalid filters or database error | ``` -------------------------------- ### Create Sequence Macro Request Body Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md This is an example of the JSON array format expected for the request body when creating a cast sequence macro. Each object represents a skill with its level and cooldown. ```json [ { "skillName": "Fireball", "level": 1, "cooldown": 300 }, { "skillName": "Frostbolt", "level": 2, "cooldown": 200 } ] ``` -------------------------------- ### Actual MySQL Connection String Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Illustrates the actual connection string used in the application, incorporating configuration variables for user, password, host, port, and database name, while retaining fixed parameters for charset, parseTime, and loc. ```sql {DbUser}:{DbPwd}@tcp(127.0.0.1:3306)/{DbName}?charset=utf8&parseTime=True&loc=Local ``` -------------------------------- ### PreCreate Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Handles pre-creation requests for macros, querying the MacrosOld60 table. ```APIDOC ## GET /macro60/preCreate ### Description Handles requests for pre-creating macros. This endpoint queries the `MacrosOld60` table and is logged with the key "macro60_precreate". ### Method GET ### Endpoint /macro60/preCreate ### Response #### Success Response (200) - Indicates successful pre-creation handling. ``` -------------------------------- ### Get Chart Data Handler - Go Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Fetches aggregated analytics data for a specified date range. It queries login logs for page views and API calls, then formats the data for display. ```go func GetChartData(c *gin.Context) { // Parses start/end dates or uses defaults (±20 days from Config.ChartDay) // Generates list of all dates in range // Queries login logs for page views (type=1): // - Counts distinct IPs per date // - Sums total visits per date // Queries login logs for API calls (type=2): // - Counts distinct IPs per date // - Sums total calls per date // Divides visit/call counts by 10 for readability // Sorts dates alphabetically // Returns three data series: IPs, Pages/10, APIs/10 } ``` -------------------------------- ### PreCreate Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Searches for verified macros based on a keyword to assist users in macro creation. ```APIDOC ## GET /macro/preCreate ### Description Searches verified macros to assist with macro creation. ### Method GET ### Endpoint /macro/preCreate ### Query Parameters - **macro** (string) - Required - Keyword to search for within macro titles or content. ### Response #### Success Response (200) - **code** (integer) - 0 for success. - **data** (array) - An array of verified macro objects, each containing details like `id`, `title`, `macro`, `author`, `updatetime`, `isVerify`, `masteryId`, and `professionId`. #### Response Example ```json { "code": 0, "data": [ { "id": 1, "title": "Healing Macro", "macro": "/cast [@target,help] Healing Touch", "author": "Healer", "updatetime": "2026-01-15T10:30:00Z", "isVerify": 1, "masteryId": 1, "professionId": 2 } ] } ``` #### Error Response (500) - **code** (integer) - 500 for internal server error. - **msg** (string) - Error message, e.g., "params is empty". ``` -------------------------------- ### JavaScript Function to Get URL Parameter Source: https://github.com/illidan33/wow_api/blob/master/public/html/wow_api/api_search_list.html A utility function to extract a specific parameter value from the current URL's query string. Useful for retrieving search terms or other dynamic parameters. ```javascript function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=(\[^&]\*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } ``` -------------------------------- ### Get Paginated Macro List Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Retrieves a paginated list of macros with various filtering options. Supports filtering by ID, verification status, profession, and mastery. Returns different data structures based on the 'v' query parameter. ```go func MacroList(c *gin.Context) { query := query.FilterParams(c) if query.Id == "" && query.IsVerify == "0" && query.ProfessionId == "0" && query.MasteryId == "0" { CreateLoginLog(c, "macro_list", 2) var macros []SimpleMacro var count int64 DB.Model(¯os).Count(&count) DB.Model(¯os).Limit(query.PageSize).Offset(query.PageSize * (query.PageNo - 1)).Find(¯os) c.JSON(http.StatusOK, Response{Code: 0, PageNo: query.PageNo, Data: macros}) return } var macros []Macros var count int64 DB.Model(¯os).Where(query.Filter).Count(&count) DB.Model(¯os).Where(query.Filter).Limit(query.PageSize).Offset(query.PageSize * (query.PageNo - 1)).Find(¯os) if query.V == "v" { c.JSON(http.StatusOK, Response{Code: 0, PageNo: query.PageNo, Data: macros}) } else { var simpleMacros []SimpleMacro for _, macro := range macros { simpleMacros = append(simpleMacros, SimpleMacro{macro.Title, macro.Macro, macro.Author}) } c.JSON(http.StatusOK, Response{Code: 0, PageNo: query.PageNo, Data: simpleMacros}) } CreateLoginLog(c, "macro_list", 2) } ``` -------------------------------- ### Initialize Vue Instance and Fetch Data Source: https://github.com/illidan33/wow_api/blob/master/public/html/macro60_tool/macro60_verify.html Initializes the Vue instance with data and methods for searching and updating macros. It also fetches the list of professions. ```javascript var vue = new Vue({ el: "#container", delimiters: ['${', '}$'], data: { professions: [], macros: [], }, methods: { search: function() { var professionId = document.getElementById("profession").value; axios.get('/macro60/macroList', { params: { isVerify: 2, professionId: professionId, v: "v", } }) .then(function(response) { // console.log(response); vue.$data.macros = response.data.data; }) .catch(function(error) { // console.log(error); }); }, update: function(id) { // console.log(id); var isVerify = document.getElementById("verify_" + id).value; var author = document.getElementById("author_" + id).value; var title = document.getElementById("title_" + id).value; var macro = document.getElementById("macro_" + id).value; axios.put('/auth/macro60', { id: parseInt(id), isVerify: parseInt(isVerify), author: author, title: title, macro: macro, } ).then(function(response) { // console.log(response); if ((response.data.code == 0) && (isVerify === 1 || isVerify === "1")) { document.getElementById("verify_" + id).parentElement.parentElement.style.display = "none"; } }); // console.log(id); } }, }) axios.get('/macro/professionList', { params: { v: 60, } }) .then(function(response) { vue.$data.professions = response.data.data; }); ``` -------------------------------- ### File Organization Structure Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/README.md Illustrates the directory structure of the Wow API project, detailing the purpose of each markdown file. ```markdown /workspace/home/output/ ├── README.md (this file) ├── 01-project-overview.md (architecture and setup) ├── 02-endpoints.md (HTTP API reference) ├── 03-types.md (data types and schemas) ├── 04-core-modules.md (module functions) ├── 05-route-handlers.md (handler details) └── 06-configuration.md (configuration reference) ``` -------------------------------- ### External Documentation Redirect Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Redirects to external WoW Gamepedia documentation based on API item ID and type. ```APIDOC ## GET /api/forgnDetail/:id ### Description Redirect to external WoW Gamepedia documentation. ### Method GET ### Endpoint /api/forgnDetail/:id ### Parameters #### Path Parameters - **id** (string) - Required - Numeric API ID #### Query Parameters - **type** (string) - Required - API type determines redirect URL pattern ### Response #### Success Response (302) - Redirect to Gamepedia #### Error Response (404) - API not found ``` -------------------------------- ### API Index Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Handles requests to the /api/, /api/view, and /api/view/:name routes. Renders API documentation pages based on the provided name, defaulting to 'home'. ```go func ApiIndex(c *gin.Context) { name := c.Param("name") if name == "" { name = "home" } htmlName := "api_" + name + ".html" CreateLoginLog(c, htmlName, 1) c.HTML(http.StatusOK, htmlName, gin.H{ "apiPage": name, }) } ``` -------------------------------- ### Define SimpleMacro60 Struct Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/03-types.md Defines the basic structure for legacy WoW macro content, identical to SimpleMacro. Used in legacy macro list responses. ```go type SimpleMacro60 struct { Title string `gorm:"column:title" json:"title" Macro string `gorm:"column:macro" json:"macro" Author string `gorm:"column:author" json:"author" } ``` -------------------------------- ### API Home Page Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Loads the main API documentation home page. ```APIDOC ## GET /api/ ### Description Load API documentation home page. ### Method GET ### Endpoint /api/ ``` -------------------------------- ### POST /macro/ Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Creates and shares a new macro. This endpoint allows users to define a macro with a title, the macro commands, author name, and optional mastery and profession IDs. ```APIDOC ## POST /macro/ ### Description Create and share a new macro. ### Method POST ### Endpoint /macro/ ### Parameters #### Request Body - **title** (string) - Required - Macro name - **macro** (string) - Required - WoW macro commands - **author** (string) - Required - Creator name - **masteryId** (int64) - Optional - Specialization/mastery ID - **professionId** (int64) - Optional - Class/profession ID ### Request Example ```json { "title": "My Healing Macro", "macro": "/cast [@target,help] Healing Touch", "author": "Healer", "masteryId": 1, "professionId": 2 } ``` ### Response #### Success Response (0) - **code** (integer) - Success code (0) - **data** (string) - Confirmation message (e.g., "ok") #### Response Example ```json { "code": 0, "data": "ok" } ``` #### Error Response (500) - **code** (integer) - Error code (500) - **msg** (string) - Error message (e.g., "params is error") ``` -------------------------------- ### DbConn Variable Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/04-core-modules.md Global database connection object initialized on module import using GORM ORM. It panics on connection failure, aborting startup. ```APIDOC ## DbConn Variable ### Description Global database connection object initialized on module import using GORM ORM. It panics on connection failure, aborting startup. ### Type `*gorm.DB` ### Location `modules/mysql.go:11` ### Initialization Details - Uses MySQL driver: `go-sql-driver/mysql` - Connection string format: `user:password@tcp(host:port)/database?charset=utf8&parseTime=True&loc=Local` - Host and port hardcoded to 127.0.0.1:3306 - Parses time strings to time.Time objects - Uses local timezone - Enables singular table naming - Sets logger to global.Log for SQL query logging - Enables SQL log mode if LogLevel is DebugLevel ### Usage ```go import "github.com/illidan33/wow_api/modules" var results []database.Macros modules.DbConn.Where("is_verify = ?", 1).Find(&results) ``` ``` -------------------------------- ### Toggle Log to File Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/06-configuration.md Enable or disable writing logs to a file. Set to 'true' to write logs to the file specified by LogPath, or 'false' for console-only output. ```go global.Config.IsSaveLog = true/false ``` -------------------------------- ### Create Macro Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/README.md Use this endpoint to create a new macro. Refer to the POST /macro/ section in 02-endpoints.md for more details. ```http POST /macro/ Content-Type: application/json { "title": "My Macro", "macro": "/cast spell", "author": "MyName" } ``` -------------------------------- ### ApiIndex() Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Renders the main API documentation page. It can display documentation for a specific category if a name is provided. ```APIDOC ## GET /api/ ## GET /api/view ## GET /api/view/:name ### Description Renders API documentation page. It can display documentation for a specific category if a name is provided. ### Method GET ### Endpoint /api/ /api/view /api/view/:name ### Parameters #### Path Parameters - **name** (string) - Optional - API category name (defaults to "home") ### Behavior 1. Extracts route parameter `:name` (defaults to "home" if empty) 2. Constructs HTML filename: `api_{name}.html` 3. Logs page view: `CreateLoginLog(c, htmlName, 1)` 4. Renders template with: `{"apiPage": name}` ### Returns HTML response (HTTP 200) ``` -------------------------------- ### API Documentation Page Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/02-endpoints.md Loads a general API documentation page. ```APIDOC ## GET /api/view ### Description Load API documentation page (no specific API). ### Method GET ### Endpoint /api/view ``` -------------------------------- ### Use Global DB Connection Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/04-core-modules.md Accesses the global database connection to perform queries. Ensure DbConn is initialized before use. ```go import "github.com/illidan33/wow_api/modules" var results []database.Macros modules.DbConn.Where("is_verify = ?", 1).Find(&results) ``` -------------------------------- ### Generate WoW Cast Sequence Macro Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/04-core-modules.md Creates an ordered list of skill names for a WoW cast sequence macro. It considers skill priorities and cooldowns to optimize the sequence. ```go import "github.com/illidan33/wow_api/modules" sequences := []modules.MacroSequence{ {SkillName: "Fireball", Level: 1, Cooldown: 300}, {SkillName: "Frostbolt", Level: 2, Cooldown: 200}, } macros, maxTime := modules.CreateSequence(sequences) // macros = ["Fireball", "Frostbolt", ...] // maxTime = 300 (centiseconds) ``` -------------------------------- ### Create New Macro Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Handles the creation of new macros via a POST request. It expects a JSON body containing macro details and inserts the new macro into the database. Macros are initially set to unverified (IsVerify=2). ```go func CreateMacro(c *gin.Context) { var macro Macros if err := c.ShouldBindJSON(¯o); err != nil { c.JSON(http.StatusOK, Response{Code: 500, Msg: "params is error"}) return } macro.UpdateTime = time.Now() macro.IsVerify = 2 if err := DB.Create(¯o).Error; err != nil { c.JSON(http.StatusOK, Response{Code: 500, Msg: err.Error()}) return } CreateLoginLog(c, "macro_share", 2) c.JSON(http.StatusOK, Response{Code: 0, Data: "ok"}) } ``` -------------------------------- ### Create WoW Cast Sequence Macro Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Generates a WoW cast sequence macro from a list of skills. It preprocesses skill names and converts cooldowns from centiseconds to seconds for the macro format. The cooldown is used to determine the reset time for the cast sequence. ```json [ { "skillName": "Fireball", "level": 1, "cooldown": 300 }, { "skillName": "Frostbolt", "level": 2, "cooldown": 200 } ] ``` ```json { "code": 0, "text": "#showtooltip
/castsequence reset=3 Fireball,Frostbolt", "desc": "- 最后一次按键【3】秒后,将重置
- 技能按照左侧循环,时间和技能顺序可以自己修改!" } ``` -------------------------------- ### Index Route Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Handles the root path and catch-all for no routes. ```APIDOC ## GET / ### Description Handles the root path. ### Method GET ### Endpoint / ## GET * (NoRoute) ### Description Handles requests to undefined routes. ### Method GET ### Endpoint * (NoRoute) ``` -------------------------------- ### Search APIs and Events by Text Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/04-core-modules.md Searches for APIs, macros, widgets, and events based on a text pattern in their names. Combines results from different queries and includes the item type. ```go results, err := modules.GetApiListBySearchText("GetTime") for _, item := range results { fmt.Println(item.Name, item.Type) } ``` -------------------------------- ### Sequence and Logging Functions Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/04-core-modules.md Functions for creating macro sequences and logging access. ```APIDOC ## modules.CreateSequence() ### Description Generate macro skill order. ### Method Not specified (assumed internal function) ### Endpoint Not applicable ### Parameters None specified ### Request Example None specified ### Response None specified ``` ```APIDOC ## modules.CreateLoginLog() ### Description Log access asynchronously. ### Method Not specified (assumed internal function) ### Endpoint Not applicable ### Parameters None specified ### Request Example None specified ### Response None specified ``` ```APIDOC ## modules.UpdateOrCreateLog() ### Description Update or create access log. ### Method Not specified (assumed internal function) ### Endpoint Not applicable ### Parameters None specified ### Request Example None specified ### Response None specified ``` -------------------------------- ### View Macro Tool Page Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Handles requests to view macro tool pages. It supports optional authentication for the 'verify' name and renders HTML templates. Extracts a 'name' parameter from the URL, defaulting to 'home'. ```go func ViewIndex(c *gin.Context) { name := c.Param("name") if name == "" { name = "home" } if name == "verify" { token, err := c.Cookie("token") if err != nil || token == "" { c.HTML(http.StatusUnauthorized, "404.html", nil) return } if token != Config.VerifyCode { c.HTML(http.StatusUnauthorized, "404.html", nil) return } } htmlName := fmt.Sprintf("macro_%s.html", name) CreateLoginLog(c, htmlName, 1) c.HTML(http.StatusOK, htmlName, nil) } ``` -------------------------------- ### CreateSequence Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Generates a WoW cast sequence macro from a provided list of skills. It preprocesses skill names, handles cooldowns, and formats the output macro string. ```APIDOC ## POST /macro/createSequence ### Description Generates WoW cast sequence macro from skill list. ### Method POST ### Endpoint /macro/createSequence ### Request Body - **(array)** - Required - JSON array of skills with properties: `skillName` (string), `level` (integer), `cooldown` (integer, optional, defaults to 100). ### Request Example ```json [ { "skillName": "Fireball", "level": 1, "cooldown": 300 }, { "skillName": "Frostbolt", "level": 2, "cooldown": 200 } ] ``` ### Response #### Success Response (200) - **code** (integer) - 0 for success. - **text** (string) - The generated macro string. - **desc** (string) - Description of the macro behavior. #### Response Example ```json { "code": 0, "text": "#showtooltip
/castsequence reset=3 Fireball,Frostbolt", "desc": "- 最后一次按键【3】秒后,将重置
- 技能按照左侧循环,时间和技能顺序可以自己修改!" } ``` ``` -------------------------------- ### Define SimpleMacro Struct Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/03-types.md Defines the basic structure for WoW macro content, containing title, macro commands, and author. Used in default macro list responses. ```go type SimpleMacro struct { Title string `gorm:"column:title" json:"title" Macro string `gorm:"column:macro" json:"macro" Author string `gorm:"column:author" json:"author" } ``` -------------------------------- ### List APIs Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/START-HERE.txt Retrieves a list of all available APIs. ```APIDOC ## GET /api/list ### Description Lists all available APIs. ### Method GET ### Endpoint /api/list ### Response #### Success Response (200) - **code** (integer) - Indicates success (0). - **data** (array) - A list of API items. #### Response Example ```json { "code": 0, "data": [ { "name": "GetTime", "description": "Returns the current game time." } ] } ``` ``` -------------------------------- ### Foreign Detail Index Handler Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/05-route-handlers.md Handles requests to the /api/forgnDetail/:id route. Redirects to external WoW Gamepedia documentation based on API ID and type. ```go func ForeignDetailIndex(c *gin.Context) { id := c.Param("id") apiType := c.Query("type") api, err := GetApiByID(id) if err != nil { c.HTML(http.StatusNotFound, "404.html", nil) return } CreateLoginLog(c, "api_foreign.html", 1) redirectUrl := GetApiDetailUrlByID(apiType, api.Name) c.Redirect(http.StatusFound, redirectUrl) } ``` -------------------------------- ### Create Macro Source: https://github.com/illidan33/wow_api/blob/master/_autodocs/START-HERE.txt Allows users to create a new macro by providing a title, the macro content, and the author's name. ```APIDOC ## POST /macro/ ### Description Allows users to create a new macro. ### Method POST ### Endpoint /macro/ ### Parameters #### Request Body - **title** (string) - Required - The title of the macro. - **macro** (string) - Required - The content of the macro. - **author** (string) - Required - The name of the macro author. ### Request Example ```json { "title": "My Macro", "macro": "/cast spell", "author": "MyName" } ``` ### Response #### Success Response (200) - **code** (integer) - Indicates success (0). - **data** (object) - Contains the created macro details. #### Response Example ```json { "code": 0, "data": { "title": "My Macro", "macro": "/cast spell", "author": "MyName" } } ``` ```