{"id":28560391,"url":"https://github.com/hugoww/common-library","last_synced_at":"2025-06-10T09:08:20.004Z","repository":{"id":200655620,"uuid":"706004588","full_name":"HugoWw/common-library","owner":"HugoWw","description":"存放日常封装好用的公共仓库，如文件事件控制器xnotify、rest http客户端等","archived":false,"fork":false,"pushed_at":"2024-02-25T05:55:34.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-20T20:44:23.036Z","etag":null,"topics":["common-library","library"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HugoWw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-17T05:56:38.000Z","updated_at":"2024-02-25T05:37:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"cf7b0a88-4ff6-4724-9701-52d0f5ce0e92","html_url":"https://github.com/HugoWw/common-library","commit_stats":null,"previous_names":["hugoww/common-library"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoWw%2Fcommon-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoWw%2Fcommon-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoWw%2Fcommon-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoWw%2Fcommon-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HugoWw","download_url":"https://codeload.github.com/HugoWw/common-library/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoWw%2Fcommon-library/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259043780,"owners_count":22797164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["common-library","library"],"created_at":"2025-06-10T09:08:18.745Z","updated_at":"2025-06-10T09:08:19.987Z","avatar_url":"https://github.com/HugoWw.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 介绍\n\n### 存放日常项目中沉淀的公共库和工具，如系统xnotify的控制器库、http client请求的封装等\n\n---\n\n## 库功能如下：\n```\n｜_xnotify：监控文件的修改，对其允许和拒绝\n｜_utils：存放好用的小工具或者函数\n｜_httpclient: http client请求的封装，符合rest api资源的请求方式\n```\n\n\n---\n\n## http client使用示例如下：\n``` go\nimport github.com/HugoWw/common-library/httpclient\n\ntype testData1 struct {\n    UserId int    `json:\"userId\"`\n    Id     int    `json:\"id\"`\n    Title  string `json:\"title\"`\n    Bodys  string `json:\"body\"`\n}\n\nclient, err := httpclient.NewHttpClient(http.DefaultClient, 30, \"https://jsonplaceholder.typicode.com\", 5)\nif err != nil {\n    fmt.Println(\"new http client error:\", err)\n    return\n}\n\ndata1 := testData1{}\nerr = client.Get().Prefix(\"/v1\").SetPath(\"/posts/1\").Do(context.TODO()).Into(\u0026data1)\nif err != nil {\n    // cerrors.ResponseForErrorReason(err)转换client请求错误信息是为常规error类型还是自定义错误类型\n    fmt.Println(\"http client request err:\", cerrors.ResponseForErrorReason(err))\n    return\n}\n\nfmt.Printf(\"out put get data info:%+v\\n\", data1)\n```\n\n---\n\n## xnotify使用示例如下：\n``` go\nimport github.com/HugoWw/common-library/xnotify\n\nvar end chan bool = make(chan bool)\npInfoChan := make(chan xnotify.ProcInfo, 2)\nfa, err := xnotify.NewFaNotify(end, pInfoChan)\nif err != nil {\n    fmt.Println(\"NewFaNotify error:\", err)\n    os.Exit(1)\n}\n\n// 只有在对文件注册的监控事件类型为\"FAN_ACCESS_PERM|FAN_OPEN_PERM\"类型的时候\n// 需要把对这些事件类型允许,还是拒绝的结果写回到fanotify的文件描述符(即写回内核中)，从而判断进程是否有权限对文件的操作；\nerr = fa.AddMonitorFile(\"/tmp/dir1\", xnotify.FAN_ACCESS|xnotify.FAN_CLOSE_WRITE|xnotify.FAN_OPEN|xnotify.FAN_MODIFY)\nif err != nil {\n    fmt.Println(\"NewFaNotify add monitor file error:\", err)\n}\n\ngo fa.MonitorFileEvents()\ngo func() {\n    for v := range pInfoChan {\n        fmt.Printf(\"Get Fanotify Event info about process info: %+v\\n\", v)\n    }\n}()\n\nquit := make(chan os.Signal)\nsignal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)\nselect {\ncase \u003c-end:\n    fa.RemoveMonitor()\n    fa.Close()\n    close(pInfoChan)\ncase \u003c-quit:\n    fa.RemoveMonitor()\n    fa.Close()\n    close(pInfoChan)\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugoww%2Fcommon-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugoww%2Fcommon-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugoww%2Fcommon-library/lists"}