{"id":17911490,"url":"https://github.com/aojea/mem-resolver","last_synced_at":"2025-03-23T22:33:57.902Z","repository":{"id":38422267,"uuid":"411231453","full_name":"aojea/mem-resolver","owner":"aojea","description":"memresolver is an in-memory golang resolver that allows to override current golang Lookup func literals","archived":false,"fork":false,"pushed_at":"2021-09-28T15:54:57.000Z","size":21,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T23:44:41.156Z","etag":null,"topics":["dns","golang","network","resolver"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aojea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-28T10:13:59.000Z","updated_at":"2024-04-20T19:57:06.000Z","dependencies_parsed_at":"2022-08-18T08:20:31.746Z","dependency_job_id":null,"html_url":"https://github.com/aojea/mem-resolver","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aojea%2Fmem-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aojea%2Fmem-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aojea%2Fmem-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aojea%2Fmem-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aojea","download_url":"https://codeload.github.com/aojea/mem-resolver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245179748,"owners_count":20573533,"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":["dns","golang","network","resolver"],"created_at":"2024-10-28T19:38:52.841Z","updated_at":"2025-03-23T22:33:57.623Z","avatar_url":"https://github.com/aojea.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mem-resolver\n\nmemresolver is an in-memory golang resolver that allows to override current golang Lookup func literals\n\n\n## How to use it\n\nCreate your custom Lookup function, is it common to overwrite LookupIP, that is the one used by the Dialer so we can redirect custom domains, per example.\n\n```go\nfunc myLookupIP(ctx context.Context, network, host string) ([]net.IP, error) {\n\t// fqdn appends a dot\n\tif \"mycustom.mydomain\" == strings.TrimSuffix(host, \".\") {\n\t\treturn []net.IP{net.ParseIP(\"127.0.0.1\")}, nil\n\t}\n\treturn net.DefaultResolver.LookupIP(ctx, network, host)\n}\n```\n\nOnce we have our cusotm Lookup function we create a custom `net.Resolver` \n\n```go\n\tf := \u0026MemResolver{\n\t\tLookupIP: myLookupIP,\n\t}\n\t// override lookupIP\n\tresolver := NewMemoryResolver(f)\n```\n\nThis custom resolver implements a `Dial` function that can be used to override the `net.Dialer` resolver.\n\n```go\n\ttr := \u0026http.Transport{\n\t\tProxy: http.ProxyFromEnvironment,\n\t\tDialContext: (\u0026net.Dialer{\n\t\t\tTimeout:   30 * time.Second,\n\t\t\tKeepAlive: 30 * time.Second,\n\t\t\tResolver:  resolver,\n\t\t}).DialContext,\n\t}\n\tclient := \u0026http.Client{\n\t\tTransport: tr,\n\t}\n```\n\n\nCheck [example_test.go](./example_test.go) for a full example.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faojea%2Fmem-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faojea%2Fmem-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faojea%2Fmem-resolver/lists"}