美文网首页API网关Kong实践笔记
Kong[nginx]-20 插件schema.lua初探

Kong[nginx]-20 插件schema.lua初探

作者: 国服最坑开发 | 来源:发表于2019-08-27 23:15 被阅读0次

    KONG专题目录


    0x00 目的

    本文想系统的调查一下Kong插件支持的参数输入UI格式,
    顺便调查一下是否能实现自己的复杂参数的输入要求.

    0x01 先来一张效果图:
    效果图
    0x02 代码实现

    再来看一下, 是如何定制这些控制项:

    local typedefs     = require "kong.db.schema.typedefs"
    
    return {
        name   = "param_demo",
        fields = {
            {
                config = {
                    type   = "record",
                    fields = {
                        {
                            runTimes = {
                                type = "number",
                                default = 0,
                                between = {
                                    0,
                                    100
                                }
                            }
                        },
                        {
                            environment = {
                                type     = "string",
                                required = true,
                                one_of   = {
                                    "production",
                                    "development"
                                },
                                default  = "development"
                            }
                        },
                        {
                            prodMode = {
                                type     = "boolean",
                                required = true,
                                default  = false
                            }
                        },
                        {
                            httpActions = {
                                type     = "array",
                                elements = {
                                    type   = "string",
                                    one_of = {
                                        "GET",
                                        "POST"
                                    }
                                }
                            }
                        },
    
                        {
                            appSettings = {
                                type   = "record",
                                fields = {
                                    {
                                        appKey = {
                                            type = "string",
                                        }
                                    },
                                    {
                                        iOS = {
                                            type = "string"
                                        }
                                    },
                                    {
                                        Android = {
                                            type = "string"
                                        }
                                    },
                                }
                            }
                        },
                    },
                },
            },
        },
    }
    

    本来想调查一下是否能够在array下面嵌套一层record,
    代码是能正常运行, 但是可能UI过于复杂, 没有UI提示,暂时作罢.

    TODO

    调查注释部分如何编写


    KONG专题目录


    相关文章

      网友评论

        本文标题:Kong[nginx]-20 插件schema.lua初探

        本文链接:https://www.haomeiwen.com/subject/rhzyectx.html