-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:rnemeth90/rnemeth90.github.io
- Loading branch information
Showing
398 changed files
with
71,253 additions
and
94,814 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,109 @@ | ||
languageCode = "en-us" | ||
name = "GeekyRyan" | ||
baseUrl = "https://rnemeth90.github.io" | ||
title = "GeekyRyan" | ||
theme = "hugo-coder" | ||
paginate = 10 | ||
enableRobotsTXT = true | ||
|
||
[pagination] | ||
pagerSize = 10 # Added field from Coder theme | ||
|
||
[services] | ||
[services.disqus] | ||
# Enable Disqus comments | ||
# shortname = "yourdiscussshortname" # Added section from Coder theme | ||
|
||
[markup.highlight] | ||
style = "base16-snazzy" | ||
noClasses = false # Added field from Coder theme | ||
|
||
[markup.goldmark.renderer] | ||
unsafe = true # enable raw HTML in Markdown | ||
|
||
[params] | ||
author = "Ryan Nemeth" | ||
email = "[email protected]" # used for microformats | ||
avatar = "/images/bobble.jpg" # used for microformats | ||
description = "Ryan Nemeth's personal website" | ||
keywords = "blog,developer,personal,devops" | ||
info = ["Full Stack DevOps Engineer"] | ||
avatarURL = "images/bobble.jpg" # | ||
dateFormat = "2006-01-02" | ||
name = "GeekyRyan" | ||
paginationSinglePost = true | ||
style = "dark" | ||
readMore = true # show read more button | ||
readNextPosts = 5 # show 5 related posts, 0 by default | ||
disableSummary = false | ||
copyCodeButton = true # true by default | ||
rssAsSocialIcon = true | ||
since = 2012 | ||
rtl = false # Added from Coder theme | ||
colorScheme = "auto" # Added from Coder theme | ||
hideColorSchemeToggle = false # Added from Coder theme | ||
maxSeeAlsoItems = 5 # Added from Coder theme | ||
customCSS = [] # Added from Coder theme | ||
customSCSS = [] # Added from Coder theme | ||
customJS = [] # Added from Coder theme | ||
customRemoteJS = [] # Added from Coder theme | ||
|
||
[[params.social]] | ||
url = "https://github.com/rnemeth90/" | ||
name = "Github" | ||
icon = "fa-brands fa-github fa-2x" | ||
weight = 1 | ||
|
||
# [[params.social]] | ||
# name = "Twitter" | ||
# icon = "fa-brands fa-x-twitter fa-2x" | ||
# weight = 3 | ||
# url = "https://twitter.com/johndoe/" # Added from Coder theme | ||
|
||
[[params.social]] | ||
name = "LinkedIn" | ||
icon = "fa-brands fa-linkedin fa-2x" | ||
weight = 2 | ||
url = "https://www.linkedin.com/in/ryan-nemeth-b0b1504b/" | ||
|
||
[[params.social]] | ||
name = "RSS" | ||
icon = "fa-solid fa-rss fa-2x" | ||
weight = 3 | ||
url = "https://rnemeth90.github.io/index.xml" | ||
rel = "alternate" | ||
type = "application/rss+xml" # Added from Coder theme | ||
|
||
[taxonomies] | ||
category = "categories" | ||
tag = "tags" | ||
series = "series" # Added from Coder theme | ||
author = "authors" # Added from Coder theme | ||
|
||
[languages.en] | ||
languageName = ":uk:" | ||
|
||
[[languages.en.menu.main]] | ||
name = "About" | ||
weight = 1 | ||
url = "about/" | ||
|
||
[[languages.en.menu.main]] | ||
name = "Blog" | ||
weight = 2 | ||
url = "posts/" | ||
|
||
[[languages.en.menu.main]] | ||
name = "Projects" | ||
weight = 3 | ||
url = "projects/" | ||
|
||
[[languages.en.menu.main]] | ||
name = "Tags" | ||
url = "/tags/" | ||
weight = 4 | ||
|
||
# [[languages.en.menu.main]] | ||
# name = "Contact me" | ||
# weight = 5 | ||
# url = "contact/" |
This file was deleted.
Oops, something went wrong.
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,72 @@ | ||
languageCode: 'en-us' | ||
name: 'GeekyRyan' | ||
baseUrl: 'https://rnemeth90.github.io' | ||
title: 'GeekyRyan' | ||
theme: 'anubis2' | ||
paginate: 10 | ||
enableRobotsTXT: true | ||
|
||
menu: | ||
main: | ||
- identifier: archive | ||
name: Archive | ||
title: Archive | ||
url: /posts/ | ||
weight: 3 | ||
- identifier: about | ||
name: About | ||
title: about | ||
url: /about | ||
weight: 1 | ||
- identifier: tags | ||
name: Tags | ||
title: tags | ||
url: /tags/ | ||
weight: 2 | ||
|
||
taxonomies: | ||
category: 'categories' | ||
tag: 'tags' | ||
|
||
params: | ||
author: 'Ryan Nemeth' | ||
email: [email protected] # used for microformats | ||
avatar: '/images/bobble.jpg' # used for microformats | ||
description: '' | ||
dateFormat: '2006-01-02' | ||
name: 'GeekyRyan' | ||
paginationSinglePost: true | ||
style: dark | ||
readMore: true # show read more button | ||
readNextPosts: 5 # show 5 related posts, 0 by default | ||
disableSummary: false | ||
copyCodeButton: true # true by default | ||
rssAsSocialIcon: true | ||
utterancesRepo: '' # mandatory | ||
utterancesTheme: '' # optional | ||
utterancesIssue: '' # optional | ||
utterancesLabel: '' # optional | ||
isso: | ||
enabled: true # mandatory | ||
data: 'https://comments.example.com/' # mandatory | ||
jsLocation: 'https://comments.example.com/js/embed.min.js' # mandatory | ||
css: true # optional | ||
lang: 'de' # optional | ||
replyToSelf: true # mandatory | ||
requireAuthor: true # mandatory | ||
requireEmail: true # mandatory | ||
id: 'thread-id' # optional | ||
avatar: true # optional | ||
avatar-bg: '#f0f0f0' # optional | ||
feed: false # optional | ||
graphcommentId: '' | ||
social: | ||
- id: github | ||
name: rnemeth90 | ||
|
||
markup: | ||
highlight: | ||
style: 'base16-snazzy' | ||
goldmark: | ||
renderer: | ||
unsafe: true # enable raw HTML in Markdown |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,56 @@ | ||
--- | ||
title: 'Detecting MIME Types in Go' | ||
author: Ryan | ||
date: '2024-03-27' | ||
layout: post | ||
draft: false | ||
categories: | ||
- golang | ||
- web development | ||
- software development | ||
tags: | ||
- golang | ||
- web development | ||
- software development | ||
- url | ||
--- | ||
|
||
# Introduction | ||
|
||
Knowing the type of a file you're working with is not just a matter of curiosity — it's often a necessity. This is especially true when you're deciding whether or not a particular operation can be carried out on that file. Go, with its comprehensive standard library, offers a straightforward approach to identifying a file's MIME type, ensuring that developers have the tools they need to make informed decisions about file manipulation. You may expect to find this functionality in the `file` package, but you'd be wrong! Read on... | ||
|
||
## The net/http Package: Your Gateway to MIME Detection | ||
|
||
At the heart of Go's approach to MIME type detection is the `net/http` package. This package provides everything developers need for identifying file types. The method in question, `DetectContentType()`, is nothing short of a detective dedicated to uncovering the secrets held within the first 512 bytes of a file. | ||
|
||
Imagine you're downloading an image for processing from a URL, but before you proceed, you need to confirm its type. Here's how you'd *go* about it: | ||
|
||
``` | ||
resp, err := client.Get("https://rnemeth90.github.io/images/synology-cloud-sync-01.png") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer resp.Body.Close() | ||
bytes, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// detecting the MIME type | ||
mimeType := http.DetectContentType(bytes) | ||
fmt.Println(mimeType) // Voila! It's an image/png | ||
``` | ||
|
||
In this snippet, `DetectContentType()` takes the stage, examining the initial bytes of the file and returning a MIME type, such as `image/png`. Should it find itself at a loss, unable to pin down the file's type, it defaults to `application/octet-stream`, a way of saying, "This is a file, but beyond that, you're on your own." | ||
|
||
# Beyond the Basics: When You Need More | ||
|
||
While `DetectContentType()` serves well for a number of common file types, its repertoire is not unlimited. There are scenarios where you might find yourself needing to identify more obscure or specific file types. This is where the mimetype library steps in, offering a more extensive catalog of file types. If `DetectContentType()` isn't able to help you, considering this library might just be your next move. | ||
|
||
# Conclusion | ||
|
||
Go's `net/http` package, with its `DetectContentType()` method, provides a solid foundation for this task. And for those times when you need to *go* further, the `mimetype` library is there to help. | ||
|
||
Whether you're safeguarding against the wrong file types in an upload process or curating content based on its nature, understanding and utilizing MIME type detection is an invaluable skill. Thanks for reading! | ||
|
Oops, something went wrong.