123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package Product
- // 产品语言
- type ProductLang struct {
- Id int `json:"Id"`
- T_name string `json:"T_name"` // 协议语言
- T_code string `json:"T_code"` // 代码
- }
- var ProductLangList = []ProductLang{}
- // ---------------- 方法 -------------------
- func init() {
- Add(ProductLang{
- Id: 1,
- T_name: "Goland",
- T_code: "import (\n\t\"encoding/hex\"\n\t\"fmt\"\n\t\"strings\"\n)\n\n/*\n设备->平台\n*/\nfunc T(t string, b []byte) (string) {\n\treturn string(b)\n}\n\n\n/*\n平台->设备\n*/\nfunc R(sn string, b string) (string,[]byte){\n\tt := \"/\"+sn+\"/r\"\n\treturn t,[]byte(b)\n}",
- })
- Add(ProductLang{
- Id: 2,
- T_name: "C",
- T_code: "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#define LEN 1024\n\n// 设备->平台\nvoid T(const char *t, const char *b, char **r_b) {\n size_t len1 = strlen(t);\n size_t len2 = strlen(b);\n *r_b = (char *)malloc(len1 + len2 + 1);\n strcpy(*r_b, t);\n strcat(*r_b, b);\n}\n\nvoid R(const char *t, const char *b, char **r_t, char **r_b) {\n size_t len1 = strlen(t);\n size_t len2 = strlen(b);\n *r_t = (char *)malloc(len1 + 1);\n *r_b = (char *)malloc(len2 + 1);\n strcpy(*r_t, t);\n strcpy(*r_b, b);\n}",
- })
- //Add(ProductLang{
- // Id: 3,
- // T_name: "Python",
- //})
- //Add(ProductLang{
- // Id: 4,
- // T_name: "JavaScript",
- //})
- }
- // 添加
- func Add(t ProductLang) {
- ProductLangList = append(ProductLangList, t)
- }
- // 获取列表
- func ProductLangLists() (r []ProductLang, Total int64) {
- return ProductLangList, int64(len(ProductLangList))
- }
- func ProductLangFind(id int) string {
- // 遍历数组,查询数组中的元素
- for _, v := range ProductLangList {
- // 判断数组元素是否符合条件
- if v.Id == id {
- return v.T_name
- }
- }
- return ""
- }
|