<commit_before>package main

import (
  _ "os"
  "fmt"
  "log"
  "flag"
  "net/http"

  "github.com/gorilla/mux"

  "github.com/r4start/web-tracer/tracerdb"
)

func getServeAddress() (string, string, string) {
  var host string
  var port string
  var db_name string

  flag.StringVar(&host, "host", "localhost", "IP address for listening")
  flag.StringVar(&port, "port", "4000", "Port number")
  flag.StringVar(&db_name, "dbname", "tracer.db", "Database name or path")

  flag.Parse()

  return host, port, db_name
}

func main() {
  host, port, db_name := getServeAddress()

  router := mux.NewRouter()
  router.HandleFunc("/", mainPage)
  router.NotFoundHandler = http.HandlerFunc(notFoundPage)

  writeHandler, err := tracerdb.CreateDbLogHandler(db_name)
  if err != nil {
    log.Fatal(err)
  } else {
    router.Handle("/terminal/{id:[0-9]+}", writeHandler)
  }

  http.Handle("/", router)

  bind := fmt.Sprintf("%s:%s", host, port)
  
  fmt.Printf("Listening on %s. Use database %s", bind, db_name)
  
  err = http.ListenAndServe(bind, nil)
  
  if err != nil {
    panic(err)
  }
}

func mainPage(res http.ResponseWriter, req *http.Request) {
  fmt.Fprintf(res, "Web tracer main page.")
}

func notFoundPage(res http.ResponseWriter, req *http.Request) {
  header := res.Header()
  header.Add("Location", "http://localhost")
  res.WriteHeader(302)
}<commit_msg>Added correct redirection.<commit_after>package main

import (
  "fmt"
  "log"
  "flag"
  "net/http"

  "github.com/gorilla/mux"

  "github.com/r4start/web-tracer/tracerdb"
)

func getServeAddress() (string, string, string) {
  var host string
  var port string
  var db_name string

  flag.StringVar(&host, "host", "localhost", "IP address for listening")
  flag.StringVar(&port, "port", "4000", "Port number")
  flag.StringVar(&db_name, "dbname", "tracer.db", "Database name or path")

  flag.Parse()

  return host, port, db_name
}

func main() {
  host, port, db_name := getServeAddress()

  router := mux.NewRouter()
  router.HandleFunc("/", mainPage)
  router.NotFoundHandler = http.HandlerFunc(notFoundPage)

  writeHandler, err := tracerdb.CreateDbLogHandler(db_name)
  if err != nil {
    log.Fatal(err)
  } else {
    router.Handle("/terminal/{id:[0-9]+}", writeHandler)
  }

  http.Handle("/", router)

  bind := fmt.Sprintf("%s:%s", host, port)
  
  fmt.Printf("Listening on %s. Use database %s", bind, db_name)
  
  err = http.ListenAndServe(bind, nil)
  
  if err != nil {
    panic(err)
  }
}

func mainPage(res http.ResponseWriter, req *http.Request) {
  fmt.Fprintf(res, "Web tracer main page.")
}

func notFoundPage(res http.ResponseWriter, req *http.Request) {
  res.Header().Add("Location", "http://" + req.Host)
  res.WriteHeader(302)
}
{'fraction_non_alphanumeric': 0.160982764943161, 'fraction_numerical': 0.007334066740007334, 'mean_word_length': 3.906474820143885, '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': '1582900', 'n_tokens_mistral': 1008, 'n_tokens_neox': 970, 'n_words': 222}