github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/daemon/routes.go (about)

     1  // Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved.
     2  // Use of this source code is governed by a license that can
     3  // be found in the LICENSE file.
     4  /*
     5   * Parts of this file were auto generated. Edit only those parts of
     6   * the code inside of 'EXISTING_CODE' tags.
     7   */
     8  
     9  package daemonPkg
    10  
    11  import (
    12  	// EXISTING_CODE
    13  	"errors"
    14  	"net/http"
    15  
    16  	// EXISTING_CODE
    17  
    18  	abisPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/abis"
    19  	blocksPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/blocks"
    20  	chunksPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/chunks"
    21  	configPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/config"
    22  	explorePkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/explore"
    23  	exportPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/export"
    24  	initPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/init"
    25  	listPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/list"
    26  	logsPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/logs"
    27  	monitorsPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/monitors"
    28  	namesPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/names"
    29  	receiptsPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/receipts"
    30  	scrapePkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/scrape"
    31  	slurpPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/slurp"
    32  	statePkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/state"
    33  	statusPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/status"
    34  	tokensPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/tokens"
    35  	tracesPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/traces"
    36  	transactionsPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/transactions"
    37  	whenPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/when"
    38  )
    39  
    40  // Route A structure to hold the API's routes
    41  type Route struct {
    42  	Name        string
    43  	Method      string
    44  	Pattern     string
    45  	HandlerFunc http.HandlerFunc
    46  }
    47  
    48  var routes = []Route{
    49  	{"RouteList", "GET", "/list", func(w http.ResponseWriter, r *http.Request) {
    50  		if err := listPkg.ServeList(w, r); err != nil {
    51  			RespondWithError(w, http.StatusInternalServerError, err)
    52  		}
    53  	}},
    54  	{"RouteExport", "GET", "/export", func(w http.ResponseWriter, r *http.Request) {
    55  		if err := exportPkg.ServeExport(w, r); err != nil {
    56  			RespondWithError(w, http.StatusInternalServerError, err)
    57  		}
    58  	}},
    59  	{"RouteMonitors", "GET", "/monitors", func(w http.ResponseWriter, r *http.Request) {
    60  		if err := monitorsPkg.ServeMonitors(w, r); err != nil {
    61  			RespondWithError(w, http.StatusInternalServerError, err)
    62  		}
    63  	}},
    64  	{"RouteNames", "GET", "/names", func(w http.ResponseWriter, r *http.Request) {
    65  		if err := namesPkg.ServeNames(w, r); err != nil {
    66  			RespondWithError(w, http.StatusInternalServerError, err)
    67  		}
    68  	}},
    69  	{"RouteAbis", "GET", "/abis", func(w http.ResponseWriter, r *http.Request) {
    70  		if err := abisPkg.ServeAbis(w, r); err != nil {
    71  			RespondWithError(w, http.StatusInternalServerError, err)
    72  		}
    73  	}},
    74  	{"RouteBlocks", "GET", "/blocks", func(w http.ResponseWriter, r *http.Request) {
    75  		if err := blocksPkg.ServeBlocks(w, r); err != nil {
    76  			RespondWithError(w, http.StatusInternalServerError, err)
    77  		}
    78  	}},
    79  	{"RouteTransactions", "GET", "/transactions", func(w http.ResponseWriter, r *http.Request) {
    80  		if err := transactionsPkg.ServeTransactions(w, r); err != nil {
    81  			RespondWithError(w, http.StatusInternalServerError, err)
    82  		}
    83  	}},
    84  	{"RouteReceipts", "GET", "/receipts", func(w http.ResponseWriter, r *http.Request) {
    85  		if err := receiptsPkg.ServeReceipts(w, r); err != nil {
    86  			RespondWithError(w, http.StatusInternalServerError, err)
    87  		}
    88  	}},
    89  	{"RouteLogs", "GET", "/logs", func(w http.ResponseWriter, r *http.Request) {
    90  		if err := logsPkg.ServeLogs(w, r); err != nil {
    91  			RespondWithError(w, http.StatusInternalServerError, err)
    92  		}
    93  	}},
    94  	{"RouteTraces", "GET", "/traces", func(w http.ResponseWriter, r *http.Request) {
    95  		if err := tracesPkg.ServeTraces(w, r); err != nil {
    96  			RespondWithError(w, http.StatusInternalServerError, err)
    97  		}
    98  	}},
    99  	{"RouteWhen", "GET", "/when", func(w http.ResponseWriter, r *http.Request) {
   100  		if err := whenPkg.ServeWhen(w, r); err != nil {
   101  			RespondWithError(w, http.StatusInternalServerError, err)
   102  		}
   103  	}},
   104  	{"RouteState", "GET", "/state", func(w http.ResponseWriter, r *http.Request) {
   105  		if err := statePkg.ServeState(w, r); err != nil {
   106  			RespondWithError(w, http.StatusInternalServerError, err)
   107  		}
   108  	}},
   109  	{"RouteTokens", "GET", "/tokens", func(w http.ResponseWriter, r *http.Request) {
   110  		if err := tokensPkg.ServeTokens(w, r); err != nil {
   111  			RespondWithError(w, http.StatusInternalServerError, err)
   112  		}
   113  	}},
   114  	{"RouteConfig", "GET", "/config", func(w http.ResponseWriter, r *http.Request) {
   115  		if err := configPkg.ServeConfig(w, r); err != nil {
   116  			RespondWithError(w, http.StatusInternalServerError, err)
   117  		}
   118  	}},
   119  	{"RouteStatus", "GET", "/status", func(w http.ResponseWriter, r *http.Request) {
   120  		if err := statusPkg.ServeStatus(w, r); err != nil {
   121  			RespondWithError(w, http.StatusInternalServerError, err)
   122  		}
   123  	}},
   124  	{"RouteScrape", "GET", "/scrape", func(w http.ResponseWriter, r *http.Request) {
   125  		if err := scrapePkg.ServeScrape(w, r); err != nil {
   126  			RespondWithError(w, http.StatusInternalServerError, err)
   127  		}
   128  	}},
   129  	{"RouteChunks", "GET", "/chunks", func(w http.ResponseWriter, r *http.Request) {
   130  		if err := chunksPkg.ServeChunks(w, r); err != nil {
   131  			RespondWithError(w, http.StatusInternalServerError, err)
   132  		}
   133  	}},
   134  	{"RouteInit", "GET", "/init", func(w http.ResponseWriter, r *http.Request) {
   135  		if err := initPkg.ServeInit(w, r); err != nil {
   136  			RespondWithError(w, http.StatusInternalServerError, err)
   137  		}
   138  	}},
   139  	{"RouteExplore", "GET", "/explore", func(w http.ResponseWriter, r *http.Request) {
   140  		if err := explorePkg.ServeExplore(w, r); err != nil {
   141  			RespondWithError(w, http.StatusInternalServerError, err)
   142  		}
   143  	}},
   144  	{"RouteSlurp", "GET", "/slurp", func(w http.ResponseWriter, r *http.Request) {
   145  		if err := slurpPkg.ServeSlurp(w, r); err != nil {
   146  			RespondWithError(w, http.StatusInternalServerError, err)
   147  		}
   148  	}},
   149  
   150  	// EXISTING_CODE
   151  	{"Index", "GET", "/", func(w http.ResponseWriter, r *http.Request) {
   152  		http.Redirect(w, r, "https://trueblocks.io/docs/", http.StatusMovedPermanently)
   153  	}},
   154  	{"Websockets", "GET", "/websocket", func(w http.ResponseWriter, r *http.Request) {
   155  		HandleWebsockets(connectionPool, w, r)
   156  	}},
   157  	{"DeleteMonitors", "DELETE", "/monitors", func(w http.ResponseWriter, r *http.Request) {
   158  		if err := monitorsPkg.ServeMonitors(w, r); err != nil {
   159  			RespondWithError(w, http.StatusInternalServerError, err)
   160  		}
   161  	}},
   162  	{"CreateName", "POST", "/names", func(w http.ResponseWriter, r *http.Request) {
   163  		if err := namesPkg.ServeNames(w, r); err != nil {
   164  			RespondWithError(w, http.StatusInternalServerError, err)
   165  		}
   166  	}},
   167  	{"EditName", "PUT", "/names", func(w http.ResponseWriter, r *http.Request) {
   168  		if err := namesPkg.ServeNames(w, r); err != nil {
   169  			RespondWithError(w, http.StatusInternalServerError, err)
   170  		}
   171  	}},
   172  	{"DeleteName", "DELETE", "/names", func(w http.ResponseWriter, r *http.Request) {
   173  		params := r.URL.Query()
   174  		if !params.Has("delete") && !params.Has("undelete") && !params.Has("remove") {
   175  			RespondWithError(
   176  				w,
   177  				http.StatusBadRequest,
   178  				errors.New("one of following parameters is required: delete, undelete, remove"),
   179  			)
   180  			return
   181  		}
   182  
   183  		if err := namesPkg.ServeNames(w, r); err != nil {
   184  			RespondWithError(w, http.StatusInternalServerError, err)
   185  		}
   186  	}},
   187  	// EXISTING_CODE
   188  }
   189  
   190  // EXISTING_CODE
   191  // By removing, inserting into, or altering any lines of code in this
   192  // repo without preserving the license, you are violating the terms of
   193  // our usage license. Don't do it.
   194  // EXISTING_CODE