-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from hearchco/as/feat/favicon-proxy
feat: Favicons proxy
- Loading branch information
Showing
4 changed files
with
154 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package result | ||
|
||
type GeneralOutput struct { | ||
generalOutputJSON | ||
} | ||
|
||
type generalOutputJSON struct { | ||
General | ||
|
||
FaviconHash string `json:"favicon_hash,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package moreurls | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
const ( | ||
faviconVerifierPrefix = "favicon-verify://" | ||
uriPattern = "^(http(s?))(://)([^/]+)" | ||
) | ||
|
||
// Prepends the URI with the favicon-verify prefix. | ||
func GetURIToVerify(urll string) (string, error) { | ||
uri, err := GetURI(urll) | ||
if err != nil { | ||
return "", err | ||
} else { | ||
return faviconVerifierPrefix + uri, nil | ||
} | ||
} | ||
|
||
// Extracts the URI from the URL. | ||
// https://www.example.com/some/path -> https://www.example.com | ||
func GetURI(urll string) (string, error) { | ||
re := regexp.MustCompile(uriPattern) | ||
ss := re.FindString(urll) | ||
if ss == "" { | ||
return "", fmt.Errorf("failed to extract URI from URL") | ||
} else { | ||
return ss, nil | ||
} | ||
} |