MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_realistic_go_server

Function test_realistic_go_server

atomic-semantic/src/parsers/go.rs:717–855  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

715
716 #[test]
717 fn test_realistic_go_server() {
718 let mut parser = GoParser::new();
719 let source = r#"
720package main
721
722import (
723 "encoding/json"
724 "fmt"
725 "log"
726 "net/http"
727)
728
729const (
730 DefaultPort = 8080
731 MaxBodySize = 1 << 20 // 1 MB
732)
733
734// ErrNotFound is returned when a resource is not found.
735var ErrNotFound = fmt.Errorf("not found")
736
737// User represents a user in the system.
738type User struct {
739 ID string `json:"id"`
740 Name string `json:"name"`
741 Email string `json:"email"`
742}
743
744// UserStore defines the interface for user persistence.
745type UserStore interface {
746 Get(id string) (*User, error)
747 Save(user *User) error
748 Delete(id string) error
749}
750
751// Handler wraps function for convenience.
752type Handler func(w http.ResponseWriter, r *http.Request)
753
754// Server holds the HTTP server state.
755type Server struct {
756 store UserStore
757 port int
758}
759
760// NewServer creates a new Server with the given store.
761func NewServer(store UserStore) *Server {
762 return &Server{store: store, port: DefaultPort}
763}
764
765// Start begins listening for HTTP requests.
766func (s *Server) Start() error {
767 addr := fmt.Sprintf(":%d", s.port)
768 log.Printf("Listening on %s", addr)
769 return http.ListenAndServe(addr, nil)
770}
771
772// HandleGetUser handles GET /users/:id requests.
773func (s *Server) HandleGetUser(w http.ResponseWriter, r *http.Request) {
774 user, err := s.store.Get(r.URL.Query().Get("id"))

Callers

nothing calls this directly

Calls 4

extractMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected