For more than two centuries, the Tokugawa shogunate kept Japan closed to foreign commerce, with the Netherlands and China as the only exceptions. In 1854 that changed. Japan signed friendship treaties one after another with the United States, the United Kingdom and Russia, and Hakodate became a port open to foreign trade. The shogunate sent high-ranking officials, called Hakodate magistrates, to run the show. They were responsible for negotiating with foreign countries, defending the shores and administering the city. Their government office needed a home, and the plan was to place it inland, away from the port and the downtown area, protected by a fort. That is the origin of Goryōkaku. It began life as an administrative center, but defense was the primary consideration. Western ships were now arriving in the harbor, and the shogunate wanted its office to be able to defend itself. So Goryōkaku was built as a government headquarters wrapped in fortress walls.