<commit_before>package main

import (
	"github.com/phzfi/RIC/server/cache"
	"github.com/phzfi/RIC/server/logging"
	"gopkg.in/tylerb/graceful.v1"
	"io"
	"log"
	"net/http"
	"strconv"
	"sync/atomic"
	"time"
)

// MyHandler type is used to encompass HandlerFunc interface.
// In the future this type will probably contain pointers to
// services provided by this program (image cache).
type MyHandler struct {

	// Service started
	started time.Time

	// Request count (statistics)
	requests uint64

	images cache.AmbiguousSizeImageCache
}

// ServeHTTP is called whenever there is a new request.
// This is quite similar to JavaEE Servlet interface.
// TODO: Check that ServeHTTP is called inside a goroutine?
func (h *MyHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	method := request.Method

	// In the future we can use requester can detect request spammers!
	// requester := request.RemoteAddr

	// Increase request count
	count := &(h.requests)
	atomic.AddUint64(count, 1)

	if method == "GET" {

		url := request.URL
		filename := url.Path

		// GET parameters
		query := url.Query()

		h.RetrieveImage(writer, filename, getUintParam(query, "width"), getUintParam(query, "height"))

	} else if method == "POST" {
		// POST is currently unused so we can use this for testing
		h.RetrieveHello(writer)
	}
}

// Returns a request parameter as *uint; nil if the parameter is not properly specified.
func getUintParam(params map[string][]string, name string) (result *uint) {

	if values := params["width"]; len(values) != 0 {
		asUint, err := strconv.ParseUint(values[0], 10, 32)
		if err == nil {
			*result = uint(asUint)
		}
	}
	return
}

// Respond to POST message by saying Hello
func (h MyHandler) RetrieveHello(writer http.ResponseWriter) {
	result := "Hello world!"
	_, err := io.WriteString(writer, result)
	if err != nil {
		log.Println(err)<commit_msg>fixed nil dereference and ignored argument in function.<commit_after>package main

import (
	"github.com/phzfi/RIC/server/cache"
	"github.com/phzfi/RIC/server/logging"
	"gopkg.in/tylerb/graceful.v1"
	"io"
	"log"
	"net/http"
	"strconv"
	"sync/atomic"
	"time"
)

// MyHandler type is used to encompass HandlerFunc interface.
// In the future this type will probably contain pointers to
// services provided by this program (image cache).
type MyHandler struct {

	// Service started
	started time.Time

	// Request count (statistics)
	requests uint64

	images cache.AmbiguousSizeImageCache
}

// ServeHTTP is called whenever there is a new request.
// This is quite similar to JavaEE Servlet interface.
// TODO: Check that ServeHTTP is called inside a goroutine?
func (h *MyHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	method := request.Method

	// In the future we can use requester can detect request spammers!
	// requester := request.RemoteAddr

	// Increase request count
	count := &(h.requests)
	atomic.AddUint64(count, 1)

	if method == "GET" {

		url := request.URL
		filename := url.Path

		// GET parameters
		query := url.Query()

		h.RetrieveImage(writer, filename, getUintParam(query, "width"), getUintParam(query, "height"))

	} else if method == "POST" {
		// POST is currently unused so we can use this for testing
		h.RetrieveHello(writer)
	}
}

// Returns a request parameter as *uint; nil if the parameter is not properly specified.
func getUintParam(params map[string][]string, name string) (result *uint) {

	if values := params[name]; len(values) != 0 {
		asUint, err := strconv.ParseUint(values[0], 10, 32)
		if err == nil {
			u := uint(asUint)
			result = &u
		}
	}
	return
}

// Respond to POST message by saying Hello
func (h MyHandler) RetrieveHello(writer http.ResponseWriter) {
	result := "Hello world!"
	_, err := io.WriteString(writer, result)
	if err != nil {
		log.Println(err)
{'fraction_non_alphanumeric': 0.11686274509803922, 'fraction_numerical': 0.006274509803921568, 'mean_word_length': 3.873885350318471, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2795391', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1206, 'n_words': 404}