Skip to content
A image cache server for transfer HTTP image to HTTPS in Heroku
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
Godeps Fixed godep Oct 1, 2017
.gitignore u Jun 23, 2019
.travis.yml
LICENSE
Procfile
README.md Update README.md Jun 6, 2019
app.json
httpapi.go
imgcache.go
imgcache_test.go Support PNG Jun 26, 2019
main.go Support PNG Jun 26, 2019

README.md

img-cache-server: A web image trasfer to HTTPS link

GoDoc Build Status

How to use it

  • "https://YOUR_ADDR/url? + Your_Http_Img_Address": Return a id of image cache. (Img_Cache_ID)
  • "https://YOUR_ADDR/img? + Img_Cache_ID.jpg": Cache image content.
  • "https://YOUR_ADDR/go? + Your_Http_Img_Address": Provide https image on-fly, it may take a while if your image size is large.

So you can easily to cache any HTTP image and forward to HTTPS if you hosted on Heroko.

Enjoy it.

Installation and Usage

Deploy

Sample code how to use this server.

var ImgSrv string = "YOUR_DEPLOY_ADDRESS"


func getSecureImageAddress(oriAdd string) string {
	eURL := url.QueryEscape(oriAdd)
	imgGetUrl := fmt.Sprintf("%surl?%s", ImgSrv, eURL)
	log.Println("eURL:", eURL, " url:", imgGetUrl, " ImgApi:", ImgSrv)

	response, err := http.Get(imgGetUrl)
	if err != nil {
		log.Println("Error while downloading:", err)
		return ""
	}
	defer response.Body.Close()

	if response.StatusCode != 200 {
		return ""
	}

	totalBody, err := ioutil.ReadAll(response.Body)
	if err != nil {
		log.Println("Error while parsing:", err)
		return ""
	}
	log.Println("Got data:", string(totalBody))
	return fmt.Sprintf("%simgs?%s.jpg", ImgSrv, string(totalBody))

}

Inspired by

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.